@@ -106,13 +106,8 @@ let NewByRefKindInferenceType (g: TcGlobals) m =
106106
107107let NewInferenceTypes l = l |> List.map ( fun _ -> NewInferenceType ())
108108
109- // QUERY: should 'rigid' ever really be 'true'? We set this when we know
110- // we are going to have to generalize a typar, e.g. when implementing a
111- // abstract generic method slot. But we later check the generalization
112- // condition anyway, so we could get away with a non-rigid typar. This
113- // would sort of be cleaner, though give errors later.
114109let FreshenAndFixupTypars ( traitCtxt : ITraitContext option ) m rigid fctps tinst tpsorig =
115- let copy_tyvar ( tp : Typar ) = NewCompGenTypar ( tp.Kind, rigid, tp.StaticReq, ( if rigid= TyparRigidity.Rigid then TyparDynamicReq.Yes else TyparDynamicReq.No), false )
110+ let copy_tyvar ( tp : Typar ) = NewCompGenTypar ( tp.Kind, rigid, tp.StaticReq, ( if rigid= TyparRigidity.Rigid then TyparDynamicReq.Yes else TyparDynamicReq.No), false )
116111 let tps = tpsorig |> List.map copy_ tyvar
117112 let renaming , tinst = FixupNewTypars traitCtxt m fctps tinst tpsorig tps
118113 tps, renaming, tinst
@@ -322,13 +317,13 @@ let rec occursCheck g un ty =
322317type PermitWeakResolution =
323318
324319 /// Represents the point where we are generalizing inline code
325- | YesAtInlineGeneralization
320+ | LegacyYesAtInlineGeneralization
326321
327322 /// Represents points where we are choosing a default solution to trait constraints
328323 | YesAtChooseSolution
329324
330- /// Represents legacy invocations of the constraint solver during codegen
331- | YesAtCodeGen
325+ /// Represents invocations of the constraint solver during codegen or inlining to determine witnesses
326+ | LegacyYesAtCodeGen
332327
333328 /// No weak resolution allowed
334329 | No
@@ -339,15 +334,15 @@ type PermitWeakResolution =
339334 if g.langVersion.SupportsFeature LanguageFeature.ExtensionConstraintSolutions then
340335 match x with
341336 | YesAtChooseSolution -> true
342- | YesAtInlineGeneralization
343- | YesAtCodeGen
337+ | LegacyYesAtCodeGen
338+ | LegacyYesAtInlineGeneralization
344339 | No -> false
345340 else
346341 //legacy
347342 match x with
348- | YesAtChooseSolution -> true
349- | YesAtCodeGen -> true
350- | YesAtInlineGeneralization -> true
343+ | YesAtChooseSolution
344+ | LegacyYesAtCodeGen
345+ | LegacyYesAtInlineGeneralization -> true
351346 | No -> false
352347
353348
@@ -447,7 +442,7 @@ let IsBinaryOpArgTypePair p1 p2 permitWeakResolution minfos g ty1 ty2 =
447442
448443 // During regular canonicalization (weak resolution) we don't do any check on the other type at all - we
449444 // ignore the possibility that method overloads may resolve the constraint
450- | PermitWeakResolution.YesAtInlineGeneralization
445+ | PermitWeakResolution.LegacyYesAtInlineGeneralization
451446 | PermitWeakResolution.YesAtChooseSolution ->
452447 // weak resolution lets the other type be a variable type
453448 isTyparTy g ty2 ||
@@ -457,7 +452,7 @@ let IsBinaryOpArgTypePair p1 p2 permitWeakResolution minfos g ty1 ty2 =
457452 typeEquivAux EraseMeasures g ty1 ty2
458453
459454 // During codegen we only apply a builtin resolution if both the types are correct
460- | PermitWeakResolution.YesAtCodeGen ->
455+ | PermitWeakResolution.LegacyYesAtCodeGen ->
461456 p2 ty2 &&
462457 // All built-in rules only apply in cases where left and right operator types are equal (after
463458 // erasing units)
@@ -1853,7 +1848,7 @@ and SolveRelevantMemberConstraintsForTypar (csenv:ConstraintSolverEnv) ndeep (pe
18531848 SolveMemberConstraint csenv true permitWeakResolution ( ndeep+ 1 ) m2 trace traitInfo)
18541849
18551850and CanonicalizeRelevantMemberConstraints ( csenv : ConstraintSolverEnv ) ndeep trace tps isInline =
1856- let permitWeakResolution = ( if isInline then PermitWeakResolution.YesAtInlineGeneralization else PermitWeakResolution.YesAtChooseSolution)
1851+ let permitWeakResolution = ( if isInline then PermitWeakResolution.LegacyYesAtInlineGeneralization else PermitWeakResolution.YesAtChooseSolution)
18571852 SolveRelevantMemberConstraints csenv ndeep permitWeakResolution trace tps
18581853
18591854and AddMemberConstraint ( csenv : ConstraintSolverEnv ) ndeep m2 ( trace : OptionalTrace ) traitInfo support ( frees : Typar list ) =
@@ -3148,17 +3143,6 @@ let CreateCodegenState tcVal g amap =
31483143 ExtraCxs = HashMultiMap( 10 , HashIdentity.Structural)
31493144 InfoReader = new InfoReader( g, amap) }
31503145
3151- let CodegenWitnessThatTypeSupportsTraitConstraint tcVal g amap m ( traitInfo : TraitConstraintInfo ) argExprs = trackErrors {
3152- let css = CreateCodegenState tcVal g amap
3153-
3154- let csenv = MakeConstraintSolverEnv ContextInfo.NoContext css m ( DisplayEnv.Empty g)
3155-
3156- let! _res = SolveMemberConstraint csenv true PermitWeakResolution.YesAtCodeGen 0 m NoTrace traitInfo
3157-
3158- let sln = GenWitnessExpr amap g m traitInfo argExprs
3159- return sln
3160- }
3161-
31623146let ChooseTyparSolutionAndSolve css denv tp =
31633147 let g = css.g
31643148 let amap = css.amap
@@ -3169,6 +3153,25 @@ let ChooseTyparSolutionAndSolve css denv tp =
31693153 ( fun err -> ErrorD( ErrorFromApplyingDefault( g, denv, tp, max, err, m)))
31703154 |> RaiseOperationResult
31713155
3156+ let CodegenWitnessThatTypeSupportsTraitConstraint tcVal g amap m ( traitInfo : TraitConstraintInfo ) argExprs = trackErrors {
3157+ let css = CreateCodegenState tcVal g amap
3158+ let denv = DisplayEnv.Empty g
3159+
3160+ let csenv = MakeConstraintSolverEnv ContextInfo.NoContext css m denv
3161+
3162+ let! _res = SolveMemberConstraint csenv true PermitWeakResolution.LegacyYesAtCodeGen 0 m NoTrace traitInfo
3163+ let sln = GenWitnessExpr amap g m traitInfo argExprs
3164+
3165+ sln |> Option.iter ( fun slnExpr ->
3166+ let unsolved = FSharp.Compiler.FindUnsolved.UnsolvedTyparsOfExpr g amap denv slnExpr
3167+
3168+ unsolved |> List.iter ( fun tp ->
3169+ if ( tp.Rigidity <> TyparRigidity.Rigid) && not tp.IsSolved then
3170+ ChooseTyparSolutionAndSolve css denv tp))
3171+
3172+ return sln
3173+ }
3174+
31723175let CheckDeclaredTypars denv css m typars1 typars2 =
31733176 let csenv = MakeConstraintSolverEnv ContextInfo.NoContext css m denv
31743177 TryD_ IgnoreAbortForFailedOverloadResolution
0 commit comments