Skip to content

Commit

Permalink
Reduce diff
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarfgp committed Jan 4, 2025
1 parent 106550d commit 1e3a8cd
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 32 deletions.
23 changes: 12 additions & 11 deletions src/Compiler/Checking/Expressions/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ let TcConst (cenv: cenv) (overallTy: TType) m env synConst =
| TyparKind.Type -> error(Error(FSComp.SR.tcExpectedUnitOfMeasureNotType(), m))
| TyparKind.Measure -> Measure.Const(tcref, ms.Range)

| SynMeasure.Power(measure = ms; power = exponent; range= m) -> Measure.RationalPower (tcMeasure ms, TcSynRationalConst exponent)
| SynMeasure.Power(measure = ms; power = exponent) -> Measure.RationalPower (tcMeasure ms, TcSynRationalConst exponent)
| SynMeasure.Product(measure1 = ms1; measure2 = ms2; range= m) -> Measure.Prod(tcMeasure ms1, tcMeasure ms2, m)
| SynMeasure.Divide(ms1, _, (SynMeasure.Seq (_ :: _ :: _, _) as ms2), m) ->
warning(Error(FSComp.SR.tcImplicitMeasureFollowingSlash(), m))
Expand All @@ -826,10 +826,10 @@ let TcConst (cenv: cenv) (overallTy: TType) m env synConst =
let measureTy =
match synConst with
| SynConst.Measure(synMeasure = SynMeasure.Anon _) ->
(mkWoNullAppTy tcr [TType_measure (Measure.Var(NewAnonTypar (TyparKind.Measure, m, TyparRigidity.Anon, (if iszero then TyparStaticReq.None else TyparStaticReq.HeadType), TyparDynamicReq.No)))])
(mkWoNullAppTy tcr [TType_measure (Measure.Var (NewAnonTypar (TyparKind.Measure, m, TyparRigidity.Anon, (if iszero then TyparStaticReq.None else TyparStaticReq.HeadType), TyparDynamicReq.No)))])

| SynConst.Measure(synMeasure = ms) -> mkWoNullAppTy tcr [TType_measure (tcMeasure ms)]
| _ -> mkWoNullAppTy tcr [TType_measure(Measure.One(m))]
| _ -> mkWoNullAppTy tcr [TType_measure(Measure.One m)]
unif measureTy

let expandedMeasurablesEnabled =
Expand Down Expand Up @@ -4662,14 +4662,14 @@ and TcArrayType (cenv: cenv) newOk checkConstraints occ env tpenv rank elemTy m
and TcTypeParameter kindOpt (cenv: cenv) env newOk tpenv tp =
let tpR, tpenv = TcTypeOrMeasureParameter kindOpt cenv env newOk tpenv tp
match tpR.Kind with
| TyparKind.Measure -> TType_measure (Measure.Var(tpR)), tpenv
| TyparKind.Measure -> TType_measure (Measure.Var tpR), tpenv
| TyparKind.Type -> mkTyparTy tpR, tpenv

// _ types
and TcAnonType kindOpt (cenv: cenv) newOk tpenv m =
let tp: Typar = TcAnonTypeOrMeasure kindOpt cenv TyparRigidity.Anon TyparDynamicReq.No newOk m
match tp.Kind with
| TyparKind.Measure -> TType_measure (Measure.Var(tp)), tpenv
| TyparKind.Measure -> TType_measure (Measure.Var tp), tpenv
| TyparKind.Type -> mkTyparTy tp, tpenv

and TcTypeWithConstraints (cenv: cenv) env newOk checkConstraints occ tpenv synTy synConstraints =
Expand Down Expand Up @@ -4715,7 +4715,7 @@ and TcTypeStaticConstant kindOpt tpenv c m =
errorR(Error(FSComp.SR.parsInvalidLiteralInType(), m))
NewErrorType (), tpenv
| SynConst.Int32 1, _ ->
TType_measure (Measure.One(m)), tpenv
TType_measure (Measure.One m), tpenv
| _ ->
errorR(Error(FSComp.SR.parsInvalidLiteralInType(), m))
NewErrorType (), tpenv
Expand All @@ -4736,7 +4736,7 @@ and TcTypeMeasureApp kindOpt (cenv: cenv) newOk checkConstraints occ env tpenv a
| (None | Some TyparKind.Measure), [arg2], true ->
let ms1, tpenv = TcMeasure cenv newOk checkConstraints occ env tpenv arg1 m1
let ms2, tpenv = TcMeasure cenv newOk checkConstraints occ env tpenv arg2 m
TType_measure (Measure.Prod(ms1, ms2, m)), tpenv
TType_measure (Measure.Prod(ms1, ms2, unionRanges ms1.Range ms2.Range)), tpenv

| _ ->
errorR(Error(FSComp.SR.tcTypeParameterInvalidAsTypeConstructor(), m))
Expand Down Expand Up @@ -4810,12 +4810,13 @@ and TcMeasuresAsTuple (cenv: cenv) newOk checkConstraints occ env (tpenv: Unscop
gather args tpenv ms1
| SynTupleTypeSegment.Star _ :: SynTupleTypeSegment.Type ty :: args ->
let ms1, tpenv = TcMeasure cenv newOk checkConstraints occ env tpenv ty m
gather args tpenv (Measure.Prod(acc, ms1, m))
gather args tpenv (Measure.Prod(acc, ms1, unionRanges acc.Range ms1.Range))
| SynTupleTypeSegment.Slash _ :: SynTupleTypeSegment.Type ty :: args ->
let ms1, tpenv = TcMeasure cenv newOk checkConstraints occ env tpenv ty m
gather args tpenv (Measure.Prod(acc, Measure.Inv ms1, m))
let ms2 = Measure.Inv ms1
gather args tpenv (Measure.Prod(acc, ms2, unionRanges acc.Range ms2.Range))
| _ -> failwith "impossible"
gather args tpenv (Measure.One(m))
gather args tpenv (Measure.One m)

and TcTypesOrMeasures optKinds (cenv: cenv) newOk checkConstraints occ env tpenv args m =
match optKinds with
Expand Down Expand Up @@ -5043,7 +5044,7 @@ and TcTypeApp (cenv: cenv) newOk checkConstraints occ env tpenv m tcref pathType
let tps = tinst |> List.skip pathTypeArgsLength |> List.map (fun t ->
match t with
| TType_var(typar, _)
| TType_measure(Measure.Var(typar= typar)) -> typar
| TType_measure(Measure.Var typar) -> typar
| t -> failwith $"TcTypeApp: {t}"
)

Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Checking/NameResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,7 @@ let NewErrorType () =
mkTyparTy (NewErrorTypar ())

let NewErrorMeasure () =
Measure.Var((NewErrorMeasureVar ()))
Measure.Var (NewErrorMeasureVar ())

let NewByRefKindInferenceType (g: TcGlobals) m =
let tp = Construct.NewTypar (TyparKind.Type, TyparRigidity.Flexible, SynTypar(compgenId, TyparStaticReq.HeadType, true), false, TyparDynamicReq.No, [], false, false)
Expand Down
2 changes: 0 additions & 2 deletions src/Compiler/Checking/PostInferenceChecks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ module internal FSharp.Compiler.PostTypeCheckSemanticChecks
open System
open System.Collections.Generic

open FSharp.Compiler.AttributeChecking
open FSharp.Compiler.NameResolution
open Internal.Utilities.Collections
open Internal.Utilities.Library
open Internal.Utilities.Library.Extras
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/Checking/TypeRelations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ let ChooseTyparSolutionAndRange (g: TcGlobals) amap (tp:Typar) =
let initialTy =
match tp.Kind with
| TyparKind.Type -> g.obj_ty_noNulls
| TyparKind.Measure -> TType_measure(Measure.One(m))
| TyparKind.Measure -> TType_measure(Measure.One m)
// Loop through the constraints computing the lub
(((initialTy, false), m), tp.Constraints) ||> List.fold (fun ((maxTy, isRefined), _) tpc ->
let join m x =
Expand Down Expand Up @@ -227,7 +227,7 @@ let ChooseTyparSolutionAndRange (g: TcGlobals) amap (tp:Typar) =

let ChooseTyparSolution g amap tp =
let ty, m = ChooseTyparSolutionAndRange g amap tp
if tp.Rigidity = TyparRigidity.Anon && typeEquiv g ty (TType_measure(Measure.One(m))) then
if tp.Rigidity = TyparRigidity.Anon && typeEquiv g ty (TType_measure(Measure.One m)) then
warning(Error(FSComp.SR.csCodeLessGeneric(), tp.Range))
ty

Expand Down
3 changes: 1 addition & 2 deletions src/Compiler/Checking/import.fs
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,7 @@ let rec ImportProvidedType (env: ImportMap) (m: range) (* (tinst: TypeInst) *) (
| TType_app (tcref, [ty1;ty2], _) when tyconRefEq g tcref g.measureproduct_tcr ->
let ms1: Measure = conv ty1
let ms2: Measure = conv ty2
let m = unionRanges ms1.Range ms2.Range
Measure.Prod(ms1, ms2, m)
Measure.Prod(ms1, ms2, unionRanges ms1.Range ms2.Range)
| TType_app (tcref, [ty1], _) when tyconRefEq g tcref g.measureinverse_tcr -> Measure.Inv (conv ty1)
| TType_app (tcref, [], _) when tyconRefEq g tcref g.measureone_tcr -> Measure.One(tcref.Range)
| TType_app (tcref, [], _) when tcref.TypeOrMeasureKind = TyparKind.Measure -> Measure.Const(tcref, tcref.Range)
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Service/ItemKey.fs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ and [<Sealed>] ItemKeyStoreBuilder(tcGlobals: TcGlobals) =
debug.WriteMeasure isStandalone ms

match ms with
| Measure.Var(typar = typar) ->
| Measure.Var typar ->
writeString ItemKeyTags.typeMeasureVar
writeTypar isStandalone typar
| Measure.Const(tyconRef = tcref) ->
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Symbols/Symbols.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2638,7 +2638,7 @@ type FSharpType(cenv, ty:TType) =
protect <| fun () ->
match stripTyparEqns ty with
| TType_var (tp, _)
| TType_measure (Measure.Var(typar= tp)) ->
| TType_measure (Measure.Var tp) ->
FSharpGenericParameter (cenv, tp)
| _ -> invalidOp "not a generic parameter type"

Expand Down
6 changes: 3 additions & 3 deletions src/Compiler/TypedTree/TypedTreeBasics.fs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ let KnownWithoutNull = Nullness.Known NullnessInfo.WithoutNull
let mkTyparTy (tp:Typar) =
match tp.Kind with
| TyparKind.Type -> tp.AsType KnownWithoutNull
| TyparKind.Measure -> TType_measure (Measure.Var(tp))
| TyparKind.Measure -> TType_measure (Measure.Var tp)

// For fresh type variables clear the StaticReq when copying because the requirement will be re-established through the
// process of type inference.
Expand All @@ -219,7 +219,7 @@ let tryShortcutSolvedUnitPar canShortcut (r: Typar) =
| Some (TType_measure unt) ->
if canShortcut then
match unt with
| Measure.Var(typar= r2) ->
| Measure.Var r2 ->
match r2.Solution with
| None -> ()
| Some _ as soln ->
Expand All @@ -231,7 +231,7 @@ let tryShortcutSolvedUnitPar canShortcut (r: Typar) =

let rec stripUnitEqnsAux canShortcut unt =
match unt with
| Measure.Var(typar = r) when r.IsSolved -> stripUnitEqnsAux canShortcut (tryShortcutSolvedUnitPar canShortcut r)
| Measure.Var r when r.IsSolved -> stripUnitEqnsAux canShortcut (tryShortcutSolvedUnitPar canShortcut r)
| _ -> unt

let combineNullness (nullnessOrig: Nullness) (nullnessNew: Nullness) =
Expand Down
14 changes: 7 additions & 7 deletions src/Compiler/TypedTree/TypedTreeOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ and remapMeasureAux tyenv unt =
| Measure.Prod(u1, u2, m) -> Measure.Prod(remapMeasureAux tyenv u1, remapMeasureAux tyenv u2, m)
| Measure.RationalPower(u, q) -> Measure.RationalPower(remapMeasureAux tyenv u, q)
| Measure.Inv u -> Measure.Inv(remapMeasureAux tyenv u)
| Measure.Var(typar= tp) as unt ->
| Measure.Var tp as unt ->
match tp.Solution with
| None ->
match ListAssoc.tryFind typarEq tp tyenv.tpinst with
Expand Down Expand Up @@ -476,7 +476,7 @@ let rec MeasureConExponentAfterRemapping g r ucref unt =
/// What is the contribution of unit-of-measure variable tp to unit-of-measure expression unt?
let rec MeasureVarExponent tp unt =
match stripUnitEqnsFromMeasure unt with
| Measure.Var(typar= tpR) -> if typarEq tp tpR then OneRational else ZeroRational
| Measure.Var tpR -> if typarEq tp tpR then OneRational else ZeroRational
| Measure.Inv untR -> NegRational(MeasureVarExponent tp untR)
| Measure.Prod(measure1= unt1; measure2= unt2) -> AddRational(MeasureVarExponent tp unt1) (MeasureVarExponent tp unt2)
| Measure.RationalPower(measure = untR; power= q) -> MulRational (MeasureVarExponent tp untR) q
Expand All @@ -486,7 +486,7 @@ let rec MeasureVarExponent tp unt =
let ListMeasureVarOccs unt =
let rec gather acc unt =
match stripUnitEqnsFromMeasure unt with
| Measure.Var(typar= tp) -> if List.exists (typarEq tp) acc then acc else tp :: acc
| Measure.Var tp -> if List.exists (typarEq tp) acc then acc else tp :: acc
| Measure.Prod(measure1= unt1; measure2= unt2) -> gather (gather acc unt1) unt2
| Measure.RationalPower(measure= untR) -> gather acc untR
| Measure.Inv untR -> gather acc untR
Expand All @@ -497,7 +497,7 @@ let ListMeasureVarOccs unt =
let ListMeasureVarOccsWithNonZeroExponents untexpr =
let rec gather acc unt =
match stripUnitEqnsFromMeasure unt with
| Measure.Var(typar= tp) ->
| Measure.Var tp ->
if List.exists (fun (tpR, _) -> typarEq tp tpR) acc then acc
else
let e = MeasureVarExponent tp untexpr
Expand Down Expand Up @@ -545,7 +545,7 @@ let MeasureProdOpt m1 m2 =
match m1, m2 with
| Measure.One _, _ -> m2
| _, Measure.One _ -> m1
| _, _ -> Measure.Prod (m1, m2, range0)
| _, _ -> Measure.Prod (m1, m2, unionRanges m1.Range m2.Range)

/// Construct a measure expression representing the product of a list of measures
let ProdMeasures ms =
Expand Down Expand Up @@ -581,7 +581,7 @@ let normalizeMeasure g ms =
let cs = ListMeasureConOccsWithNonZeroExponents g false ms
match vs, cs with
| [], [] -> Measure.One(ms.Range)
| [(v, e)], [] when e = OneRational -> Measure.Var(v)
| [(v, e)], [] when e = OneRational -> Measure.Var v
| vs, cs ->
List.foldBack
(fun (v, e) ->
Expand All @@ -600,7 +600,7 @@ let normalizeMeasure g ms =

let tryNormalizeMeasureInType g ty =
match ty with
| TType_measure (Measure.Var(typar= v)) ->
| TType_measure (Measure.Var v) ->
match v.Solution with
| Some (TType_measure ms) ->
v.typar_solution <- Some (TType_measure (normalizeMeasure g ms))
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/TypedTree/TypedTreePickle.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1540,7 +1540,7 @@ let p_measure_one = p_byte 4
let p_measure_varcon unt st =
match unt with
| Measure.Const(tyconRef= tcref) -> p_measure_con tcref st
| Measure.Var(typar= v) -> p_measure_var v st
| Measure.Var v -> p_measure_var v st
| _ -> pfailwith st "p_measure_varcon: expected measure variable or constructor"

// Pickle a positive integer power of a unit-of-measure variable or constructor
Expand Down Expand Up @@ -1571,7 +1571,7 @@ let rec p_normalized_measure unt st =
| Measure.Const(tyconRef= tcref) -> p_measure_con tcref st
| Measure.Inv x -> p_byte 1 st; p_normalized_measure x st
| Measure.Prod(measure1= x1; measure2= x2) -> p_byte 2 st; p_normalized_measure x1 st; p_normalized_measure x2 st
| Measure.Var(typar= v) -> p_measure_var v st
| Measure.Var v -> p_measure_var v st
| Measure.One _ -> p_measure_one st
| Measure.RationalPower(measure= x; power= q) -> p_measure_power x q st

Expand Down

0 comments on commit 1e3a8cd

Please sign in to comment.