Skip to content

Commit 0126135

Browse files
authored
Merge pull request #15658 from dotnet/merges/main-to-release/dev17.8
Merge main to release/dev17.8
2 parents c95733c + c8bc317 commit 0126135

38 files changed

+569
-121
lines changed

eng/Version.Details.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@
2929
</Dependency>
3030
</ProductDependencies>
3131
<ToolsetDependencies>
32-
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="8.0.0-beta.23364.2">
32+
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="8.0.0-beta.23369.2">
3333
<Uri>https://github.com/dotnet/arcade</Uri>
34-
<Sha>60ea5b2eca5af06fc63b250f8669d2c70179b18c</Sha>
34+
<Sha>9fba71ca242ef84c4b7696c380cc00efe734adb3</Sha>
3535
<SourceBuild RepoName="arcade" ManagedOnly="true" />
3636
</Dependency>
3737
<Dependency Name="Microsoft.SourceLink.GitHub" Version="8.0.0-beta.23361.2" CoherentParentDependency="Microsoft.DotNet.Arcade.Sdk">
3838
<Uri>https://github.com/dotnet/sourcelink</Uri>
3939
<Sha>d2e046aec870a5a7601cc51c5607f34463cc2d42</Sha>
4040
<SourceBuild RepoName="sourcelink" ManagedOnly="true" />
4141
</Dependency>
42-
<Dependency Name="Microsoft.DotNet.XliffTasks" Version="1.0.0-beta.23360.1" CoherentParentDependency="Microsoft.DotNet.Arcade.Sdk">
42+
<Dependency Name="Microsoft.DotNet.XliffTasks" Version="1.0.0-beta.23368.1" CoherentParentDependency="Microsoft.DotNet.Arcade.Sdk">
4343
<Uri>https://github.com/dotnet/xliff-tasks</Uri>
44-
<Sha>a171b61473272e5a6d272117963864ba958a012a</Sha>
44+
<Sha>3aa0b2b84cab7d94b9136547563d027fd78e82a6</Sha>
4545
<SourceBuild RepoName="xliff-tasks" ManagedOnly="true" />
4646
</Dependency>
4747
<Dependency Name="optimization.windows_nt-x64.MIBC.Runtime" Version="1.0.0-prerelease.23362.5">
-32 Bytes
Binary file not shown.

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"perl": "5.32.1.1"
1919
},
2020
"msbuild-sdks": {
21-
"Microsoft.DotNet.Arcade.Sdk": "8.0.0-beta.23364.2",
21+
"Microsoft.DotNet.Arcade.Sdk": "8.0.0-beta.23369.2",
2222
"Microsoft.DotNet.Helix.Sdk": "8.0.0-beta.23255.2"
2323
}
2424
}

src/Compiler/Checking/CheckExpressions.fs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -754,16 +754,16 @@ let ForNewConstructors tcSink (env: TcEnv) mObjTy methodName meths =
754754
/// Typecheck rational constant terms in units-of-measure exponents
755755
let rec TcSynRationalConst c =
756756
match c with
757-
| SynRationalConst.Integer i -> intToRational i
758-
| SynRationalConst.Negate c2 -> NegRational (TcSynRationalConst c2)
759-
| SynRationalConst.Rational(p, q, _) -> DivRational (intToRational p) (intToRational q)
757+
| SynRationalConst.Integer(value = i) -> intToRational i
758+
| SynRationalConst.Negate(rationalConst = c2) -> NegRational (TcSynRationalConst c2)
759+
| SynRationalConst.Rational(numerator = p; denominator = q) -> DivRational (intToRational p) (intToRational q)
760760

761761
/// Typecheck constant terms in expressions and patterns
762762
let TcConst (cenv: cenv) (overallTy: TType) m env synConst =
763763
let g = cenv.g
764764
let rec tcMeasure ms =
765765
match ms with
766-
| SynMeasure.One -> Measure.One
766+
| SynMeasure.One _ -> Measure.One
767767
| SynMeasure.Named(tc, m) ->
768768
let ad = env.eAccessRights
769769
let _, tcref = ForceRaise(ResolveTypeLongIdent cenv.tcSink cenv.nameResolver ItemOccurence.Use OpenQualified env.eNameResEnv ad tc TypeNameResolutionStaticArgsInfo.DefiniteEmpty PermitDirectReferenceToGeneratedType.No)
@@ -775,9 +775,11 @@ let TcConst (cenv: cenv) (overallTy: TType) m env synConst =
775775
| SynMeasure.Product(ms1, ms2, _) -> Measure.Prod(tcMeasure ms1, tcMeasure ms2)
776776
| SynMeasure.Divide(ms1, (SynMeasure.Seq (_ :: _ :: _, _) as ms2), m) ->
777777
warning(Error(FSComp.SR.tcImplicitMeasureFollowingSlash(), m))
778-
Measure.Prod(tcMeasure ms1, Measure.Inv (tcMeasure ms2))
778+
let factor1 = ms1 |> Option.defaultValue (SynMeasure.One Range.Zero)
779+
Measure.Prod(tcMeasure factor1, Measure.Inv (tcMeasure ms2))
779780
| SynMeasure.Divide(ms1, ms2, _) ->
780-
Measure.Prod(tcMeasure ms1, Measure.Inv (tcMeasure ms2))
781+
let factor1 = ms1 |> Option.defaultValue (SynMeasure.One Range.Zero)
782+
Measure.Prod(tcMeasure factor1, Measure.Inv (tcMeasure ms2))
781783
| SynMeasure.Seq(mss, _) -> ProdMeasures (List.map tcMeasure mss)
782784
| SynMeasure.Anon _ -> error(Error(FSComp.SR.tcUnexpectedMeasureAnon(), m))
783785
| SynMeasure.Var(_, m) -> error(Error(FSComp.SR.tcNonZeroConstantCannotHaveGenericUnit(), m))
@@ -788,10 +790,10 @@ let TcConst (cenv: cenv) (overallTy: TType) m env synConst =
788790
let unifyMeasureArg iszero tcr =
789791
let measureTy =
790792
match synConst with
791-
| SynConst.Measure(_, _, SynMeasure.Anon _) ->
793+
| SynConst.Measure(synMeasure = SynMeasure.Anon _) ->
792794
(mkAppTy tcr [TType_measure (Measure.Var (NewAnonTypar (TyparKind.Measure, m, TyparRigidity.Anon, (if iszero then TyparStaticReq.None else TyparStaticReq.HeadType), TyparDynamicReq.No)))])
793795

794-
| SynConst.Measure(_, _, ms) -> mkAppTy tcr [TType_measure (tcMeasure ms)]
796+
| SynConst.Measure(synMeasure = ms) -> mkAppTy tcr [TType_measure (tcMeasure ms)]
795797
| _ -> mkAppTy tcr [TType_measure Measure.One]
796798
unif measureTy
797799

@@ -844,43 +846,43 @@ let TcConst (cenv: cenv) (overallTy: TType) m env synConst =
844846
| SynConst.UIntPtr i ->
845847
unif g.unativeint_ty
846848
Const.UIntPtr i
847-
| SynConst.Measure(SynConst.Single f, _, _) ->
849+
| SynConst.Measure(constant = SynConst.Single f) ->
848850
unifyMeasureArg (f=0.0f) g.pfloat32_tcr
849851
Const.Single f
850-
| SynConst.Measure(SynConst.Double f, _, _) ->
852+
| SynConst.Measure(constant = SynConst.Double f) ->
851853
unifyMeasureArg (f=0.0) g.pfloat_tcr
852854
Const.Double f
853-
| SynConst.Measure(SynConst.Decimal f, _, _) ->
855+
| SynConst.Measure(constant = SynConst.Decimal f) ->
854856
unifyMeasureArg false g.pdecimal_tcr
855857
Const.Decimal f
856-
| SynConst.Measure(SynConst.SByte i, _, _) ->
858+
| SynConst.Measure(constant = SynConst.SByte i)->
857859
unifyMeasureArg (i=0y) g.pint8_tcr
858860
Const.SByte i
859-
| SynConst.Measure(SynConst.Int16 i, _, _) ->
861+
| SynConst.Measure(constant = SynConst.Int16 i) ->
860862
unifyMeasureArg (i=0s) g.pint16_tcr
861863
Const.Int16 i
862-
| SynConst.Measure(SynConst.Int32 i, _, _) ->
864+
| SynConst.Measure(constant = SynConst.Int32 i) ->
863865
unifyMeasureArg (i=0) g.pint_tcr
864866
Const.Int32 i
865-
| SynConst.Measure(SynConst.Int64 i, _, _) ->
867+
| SynConst.Measure(constant = SynConst.Int64 i) ->
866868
unifyMeasureArg (i=0L) g.pint64_tcr
867869
Const.Int64 i
868-
| SynConst.Measure(SynConst.IntPtr i, _, _) when expandedMeasurablesEnabled ->
870+
| SynConst.Measure(constant = SynConst.IntPtr i) when expandedMeasurablesEnabled ->
869871
unifyMeasureArg (i=0L) g.pnativeint_tcr
870872
Const.IntPtr i
871-
| SynConst.Measure(SynConst.Byte i, _, _) when expandedMeasurablesEnabled ->
873+
| SynConst.Measure(constant = SynConst.Byte i) when expandedMeasurablesEnabled ->
872874
unifyMeasureArg (i=0uy) g.puint8_tcr
873875
Const.Byte i
874-
| SynConst.Measure(SynConst.UInt16 i, _, _) when expandedMeasurablesEnabled ->
876+
| SynConst.Measure(constant = SynConst.UInt16 i) when expandedMeasurablesEnabled ->
875877
unifyMeasureArg (i=0us) g.puint16_tcr
876878
Const.UInt16 i
877-
| SynConst.Measure(SynConst.UInt32 i, _, _) when expandedMeasurablesEnabled ->
879+
| SynConst.Measure(constant = SynConst.UInt32 i) when expandedMeasurablesEnabled ->
878880
unifyMeasureArg (i=0u) g.puint_tcr
879881
Const.UInt32 i
880-
| SynConst.Measure(SynConst.UInt64 i, _, _) when expandedMeasurablesEnabled ->
882+
| SynConst.Measure(constant = SynConst.UInt64 i) when expandedMeasurablesEnabled ->
881883
unifyMeasureArg (i=0UL) g.puint64_tcr
882884
Const.UInt64 i
883-
| SynConst.Measure(SynConst.UIntPtr i, _, _) when expandedMeasurablesEnabled ->
885+
| SynConst.Measure(constant = SynConst.UIntPtr i) when expandedMeasurablesEnabled ->
884886
unifyMeasureArg (i=0UL) g.punativeint_tcr
885887
Const.UIntPtr i
886888
| SynConst.Char c ->

src/Compiler/Checking/TypeRelations.fs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/// constraint solving and method overload resolution.
55
module internal FSharp.Compiler.TypeRelations
66

7+
open FSharp.Compiler.Features
78
open Internal.Utilities.Collections
89
open Internal.Utilities.Library
910
open FSharp.Compiler.DiagnosticsLogger
@@ -134,50 +135,58 @@ let rec TypeFeasiblySubsumesType ndeep g amap m ty1 canCoerce ty2 =
134135
/// Here x gets a generalized type "list<'T>".
135136
let ChooseTyparSolutionAndRange (g: TcGlobals) amap (tp:Typar) =
136137
let m = tp.Range
137-
let maxTy, m =
138+
let (maxTy, isRefined), m =
138139
let initialTy =
139140
match tp.Kind with
140141
| TyparKind.Type -> g.obj_ty
141142
| TyparKind.Measure -> TType_measure Measure.One
142143
// Loop through the constraints computing the lub
143-
((initialTy, m), tp.Constraints) ||> List.fold (fun (maxTy, _) tpc ->
144+
(((initialTy, false), m), tp.Constraints) ||> List.fold (fun ((maxTy, isRefined), _) tpc ->
144145
let join m x =
145-
if TypeFeasiblySubsumesType 0 g amap m x CanCoerce maxTy then maxTy
146-
elif TypeFeasiblySubsumesType 0 g amap m maxTy CanCoerce x then x
147-
else errorR(Error(FSComp.SR.typrelCannotResolveImplicitGenericInstantiation((DebugPrint.showType x), (DebugPrint.showType maxTy)), m)); maxTy
146+
if TypeFeasiblySubsumesType 0 g amap m x CanCoerce maxTy then maxTy, isRefined
147+
elif TypeFeasiblySubsumesType 0 g amap m maxTy CanCoerce x then x, true
148+
else errorR(Error(FSComp.SR.typrelCannotResolveImplicitGenericInstantiation((DebugPrint.showType x), (DebugPrint.showType maxTy)), m)); maxTy, isRefined
148149
// Don't continue if an error occurred and we set the value eagerly
149-
if tp.IsSolved then maxTy, m else
150+
if tp.IsSolved then (maxTy, isRefined), m else
150151
match tpc with
151152
| TyparConstraint.CoercesTo(x, m) ->
152153
join m x, m
153154
| TyparConstraint.MayResolveMember(_traitInfo, m) ->
154-
maxTy, m
155+
(maxTy, isRefined), m
155156
| TyparConstraint.SimpleChoice(_, m) ->
156157
errorR(Error(FSComp.SR.typrelCannotResolveAmbiguityInPrintf(), m))
157-
maxTy, m
158+
(maxTy, isRefined), m
158159
| TyparConstraint.SupportsNull m ->
159-
maxTy, m
160+
(maxTy, isRefined), m
160161
| TyparConstraint.SupportsComparison m ->
161162
join m g.mk_IComparable_ty, m
162163
| TyparConstraint.SupportsEquality m ->
163-
maxTy, m
164+
(maxTy, isRefined), m
164165
| TyparConstraint.IsEnum(_, m) ->
165166
errorR(Error(FSComp.SR.typrelCannotResolveAmbiguityInEnum(), m))
166-
maxTy, m
167+
(maxTy, isRefined), m
167168
| TyparConstraint.IsDelegate(_, _, m) ->
168169
errorR(Error(FSComp.SR.typrelCannotResolveAmbiguityInDelegate(), m))
169-
maxTy, m
170+
(maxTy, isRefined), m
170171
| TyparConstraint.IsNonNullableStruct m ->
171172
join m g.int_ty, m
172173
| TyparConstraint.IsUnmanaged m ->
173174
errorR(Error(FSComp.SR.typrelCannotResolveAmbiguityInUnmanaged(), m))
174-
maxTy, m
175+
(maxTy, isRefined), m
175176
| TyparConstraint.RequiresDefaultConstructor m ->
176-
maxTy, m
177+
(maxTy, isRefined), m
177178
| TyparConstraint.IsReferenceType m ->
178-
maxTy, m
179+
(maxTy, isRefined), m
179180
| TyparConstraint.DefaultsTo(_priority, _ty, m) ->
180-
maxTy, m)
181+
(maxTy, isRefined), m)
182+
183+
if g.langVersion.SupportsFeature LanguageFeature.DiagnosticForObjInference then
184+
match tp.Kind with
185+
| TyparKind.Type ->
186+
if not isRefined then
187+
informationalWarning(Error(FSComp.SR.typrelNeverRefinedAwayFromTop(), m))
188+
| TyparKind.Measure -> ()
189+
181190
maxTy, m
182191

183192
let ChooseTyparSolution g amap tp =

src/Compiler/Service/ServiceInterfaceStubGenerator.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ type InterfaceData =
105105
| InterfaceData.ObjExpr (StripParenTypes ty, _) ->
106106
let rec (|RationalConst|) =
107107
function
108-
| SynRationalConst.Integer i -> string i
109-
| SynRationalConst.Rational (numerator, denominator, _) -> sprintf "(%i/%i)" numerator denominator
110-
| SynRationalConst.Negate (RationalConst s) -> sprintf "- %s" s
108+
| SynRationalConst.Integer (value = i) -> string i
109+
| SynRationalConst.Rational (numerator = numerator; denominator = denominator) -> sprintf "(%i/%i)" numerator denominator
110+
| SynRationalConst.Negate (rationalConst = (RationalConst s)) -> sprintf "- %s" s
111111

112112
let rec (|TypeIdent|_|) =
113113
function

src/Compiler/Service/ServiceParsedInputOps.fs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,21 +1841,23 @@ module ParsedInput =
18411841
List.iter walkType ts
18421842
walkMemberSig sign
18431843
walkExpr e
1844-
| SynExpr.Const (SynConst.Measure (_, _, m), _) -> walkMeasure m
1844+
| SynExpr.Const(constant = SynConst.Measure (synMeasure = m)) -> walkMeasure m
18451845
| _ -> ()
18461846

18471847
and walkMeasure measure =
18481848
match measure with
1849-
| SynMeasure.Product (m1, m2, _)
1850-
| SynMeasure.Divide (m1, m2, _) ->
1849+
| SynMeasure.Product (m1, m2, _) ->
18511850
walkMeasure m1
18521851
walkMeasure m2
1852+
| SynMeasure.Divide (m1, m2, _) ->
1853+
m1 |> Option.iter walkMeasure
1854+
walkMeasure m2
18531855
| SynMeasure.Named (longIdent, _) -> addLongIdent longIdent
18541856
| SynMeasure.Seq (ms, _) -> List.iter walkMeasure ms
18551857
| SynMeasure.Paren (m, _)
18561858
| SynMeasure.Power (m, _, _) -> walkMeasure m
18571859
| SynMeasure.Var (ty, _) -> walkTypar ty
1858-
| SynMeasure.One
1860+
| SynMeasure.One _
18591861
| SynMeasure.Anon _ -> ()
18601862

18611863
and walkSimplePat spat =

src/Compiler/SyntaxTree/SyntaxTree.fs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ type SynConst =
158158

159159
| UInt16s of uint16[]
160160

161-
| Measure of constant: SynConst * constantRange: range * SynMeasure
161+
| Measure of constant: SynConst * constantRange: range * synMeasure: SynMeasure * trivia: SynMeasureConstantTrivia
162162

163163
| SourceIdentifier of constant: string * value: string * range: range
164164

@@ -178,11 +178,11 @@ type SynMeasure =
178178

179179
| Seq of measures: SynMeasure list * range: range
180180

181-
| Divide of measure1: SynMeasure * measure2: SynMeasure * range: range
181+
| Divide of measure1: SynMeasure option * measure2: SynMeasure * range: range
182182

183183
| Power of measure: SynMeasure * power: SynRationalConst * range: range
184184

185-
| One
185+
| One of range: range
186186

187187
| Anon of range: range
188188

@@ -193,11 +193,11 @@ type SynMeasure =
193193
[<NoEquality; NoComparison; RequireQualifiedAccess>]
194194
type SynRationalConst =
195195

196-
| Integer of value: int32
196+
| Integer of value: int32 * range: range
197197

198-
| Rational of numerator: int32 * denominator: int32 * range: range
198+
| Rational of numerator: int32 * numeratorRange: range * denominator: int32 * denominatorRange: range * range: range
199199

200-
| Negate of SynRationalConst
200+
| Negate of rationalConst: SynRationalConst * range: range
201201

202202
[<RequireQualifiedAccess>]
203203
type SynAccess =

src/Compiler/SyntaxTree/SyntaxTree.fsi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ type SynConst =
170170
| UInt16s of uint16[]
171171

172172
/// Old comment: "we never iterate, so the const here is not another SynConst.Measure"
173-
| Measure of constant: SynConst * constantRange: range * SynMeasure
173+
| Measure of constant: SynConst * constantRange: range * synMeasure: SynMeasure * trivia: SynMeasureConstantTrivia
174174

175175
/// Source Line, File, and Path Identifiers
176176
/// Containing both the original value as the evaluated value.
@@ -193,13 +193,13 @@ type SynMeasure =
193193
| Seq of measures: SynMeasure list * range: range
194194

195195
/// A division of two units of measure, e.g. 'kg / m'
196-
| Divide of measure1: SynMeasure * measure2: SynMeasure * range: range
196+
| Divide of measure1: SynMeasure option * measure2: SynMeasure * range: range
197197

198198
/// A power of a unit of measure, e.g. 'kg ^ 2'
199199
| Power of measure: SynMeasure * power: SynRationalConst * range: range
200200

201201
/// The '1' unit of measure
202-
| One
202+
| One of range: range
203203

204204
/// An anonymous (inferred) unit of measure
205205
| Anon of range: range
@@ -214,11 +214,11 @@ type SynMeasure =
214214
[<NoEquality; NoComparison; RequireQualifiedAccess>]
215215
type SynRationalConst =
216216

217-
| Integer of value: int32
217+
| Integer of value: int32 * range: range
218218

219-
| Rational of numerator: int32 * denominator: int32 * range: range
219+
| Rational of numerator: int32 * numeratorRange: range * denominator: int32 * denominatorRange: range * range: range
220220

221-
| Negate of SynRationalConst
221+
| Negate of rationalConst: SynRationalConst * range: range
222222

223223
/// Represents an accessibility modifier in F# syntax
224224
[<RequireQualifiedAccess>]

src/Compiler/SyntaxTree/SyntaxTrivia.fs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,3 +395,10 @@ type SynMemberSigMemberTrivia =
395395
}
396396

397397
static member Zero: SynMemberSigMemberTrivia = { GetSetKeywords = None }
398+
399+
[<NoEquality; NoComparison>]
400+
type SynMeasureConstantTrivia =
401+
{
402+
LessRange: range
403+
GreaterRange: range
404+
}

0 commit comments

Comments
 (0)