Skip to content

Commit

Permalink
Merge pull request #15164 from dotnet/merges/main-to-release/dev17.7
Browse files Browse the repository at this point in the history
Merge main to release/dev17.7
  • Loading branch information
KevinRansom authored May 2, 2023
2 parents 0d11781 + 2496196 commit 8c91d38
Show file tree
Hide file tree
Showing 50 changed files with 423 additions and 337 deletions.
22 changes: 12 additions & 10 deletions src/Compiler/AbstractIL/ilread.fs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ type WeakByteFile(fileName: string, chunk: (int * int) option) =
let fileStamp = FileSystem.GetLastWriteTimeShim fileName

/// The weak handle to the bytes for the file
let weakBytes = WeakReference<byte[]>(null)
let weakBytes = WeakReference<byte[] MaybeNull>(null)

member _.FileName = fileName

Expand All @@ -254,7 +254,7 @@ type WeakByteFile(fileName: string, chunk: (int * int) option) =

weakBytes.SetTarget bytes

tg
nonNull tg

ByteMemory.FromArray(strongBytes).AsReadOnly()

Expand Down Expand Up @@ -941,10 +941,11 @@ let mkCacheInt32 lowMem _inbase _nm _sz =
fun f (idx: int32) ->
let cache =
match cache with
| null -> cache <- ConcurrentDictionary<int32, _>(Environment.ProcessorCount, 11)
| _ -> ()

cache
| Null ->
let v = ConcurrentDictionary<int32, _>(Environment.ProcessorCount, 11)
cache <- v
v
| NonNull v -> v

match cache.TryGetValue idx with
| true, res ->
Expand All @@ -969,10 +970,11 @@ let mkCacheGeneric lowMem _inbase _nm _sz =
fun f (idx: 'T) ->
let cache =
match cache with
| null -> cache <- ConcurrentDictionary<_, _>(Environment.ProcessorCount, 11 (* sz: int *) )
| _ -> ()

cache
| Null ->
let v = ConcurrentDictionary<_, _>(Environment.ProcessorCount, 11 (* sz: int *) )
cache <- v
v
| NonNull v -> v

match cache.TryGetValue idx with
| true, v ->
Expand Down
14 changes: 7 additions & 7 deletions src/Compiler/AbstractIL/ilreflect.fs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ type TypeBuilder with
let t = typB.CreateTypeAndLog()

let m =
if t <> null then
if box t <> null then
t.GetMethod(nm, (args |> Seq.map (fun x -> x.GetType()) |> Seq.toArray))
else
null
Expand Down Expand Up @@ -546,10 +546,10 @@ let emEnv0 =
delayedFieldInits = []
}

let envBindTypeRef emEnv (tref: ILTypeRef) (typT, typB, typeDef) =
let envBindTypeRef emEnv (tref: ILTypeRef) (typT: System.Type MaybeNull, typB, typeDef) =
match typT with
| null -> failwithf "binding null type in envBindTypeRef: %s\n" tref.Name
| _ ->
| Null -> failwithf "binding null type in envBindTypeRef: %s\n" tref.Name
| NonNull typT ->
{ emEnv with
emTypMap = Zmap.add tref (typT, typB, typeDef, None) emEnv.emTypMap
}
Expand Down Expand Up @@ -1018,7 +1018,7 @@ let queryableTypeGetMethod cenv emEnv parentT (mref: ILMethodRef) : MethodInfo =
cconv ||| BindingFlags.Public ||| BindingFlags.NonPublic,
null,
argTs,
(null: ParameterModifier[])
(null: ParameterModifier[] MaybeNull)
)
// This can fail if there is an ambiguity w.r.t. return type
with _ ->
Expand Down Expand Up @@ -1102,14 +1102,14 @@ let queryableTypeGetConstructor cenv emEnv (parentT: Type) (mref: ILMethodRef) =
parentT.GetConstructor(BindingFlags.Public ||| BindingFlags.NonPublic ||| BindingFlags.Instance, null, reqArgTs, null)

match res with
| null ->
| Null ->
error (
Error(
FSComp.SR.itemNotFoundInTypeDuringDynamicCodeGen ("constructor", mref.Name, parentT.FullName, parentT.Assembly.FullName),
range0
)
)
| _ -> res
| NonNull res -> res

let nonQueryableTypeGetConstructor (parentTI: Type) (consInfo: ConstructorInfo) : ConstructorInfo MaybeNull =
if parentTI.IsGenericType then
Expand Down
10 changes: 5 additions & 5 deletions src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4332,7 +4332,7 @@ and TcTypeOrMeasure kindOpt (cenv: cenv) newOk checkConstraints occ (iwsam: Warn
TcLongIdentType kindOpt cenv newOk checkConstraints occ iwsam env tpenv synLongId

| MultiDimensionArrayType (rank, elemTy, m) ->
TcElementType cenv newOk checkConstraints occ env tpenv rank elemTy m
TcArrayType cenv newOk checkConstraints occ env tpenv rank elemTy m

| SynType.App (StripParenTypes (SynType.LongIdent longId), _, args, _, _, postfix, m) ->
TcLongIdentAppType kindOpt cenv newOk checkConstraints occ iwsam env tpenv longId postfix args m
Expand All @@ -4353,7 +4353,7 @@ and TcTypeOrMeasure kindOpt (cenv: cenv) newOk checkConstraints occ (iwsam: Warn
TcFunctionType cenv newOk checkConstraints occ env tpenv domainTy resultTy

| SynType.Array (rank , elemTy, m) ->
TcElementType cenv newOk checkConstraints occ env tpenv rank elemTy m
TcArrayType cenv newOk checkConstraints occ env tpenv rank elemTy m

| SynType.Var (tp, _) ->
TcTypeParameter kindOpt cenv env newOk tpenv tp
Expand Down Expand Up @@ -4521,7 +4521,7 @@ and TcFunctionType (cenv: cenv) newOk checkConstraints occ env tpenv domainTy re
let tyR = mkFunTy g domainTyR resultTyR
tyR, tpenv

and TcElementType (cenv: cenv) newOk checkConstraints occ env tpenv rank elemTy m =
and TcArrayType (cenv: cenv) newOk checkConstraints occ env tpenv rank elemTy m =
let g = cenv.g
let elemTy, tpenv = TcTypeAndRecover cenv newOk checkConstraints occ WarnOnIWSAM.Yes env tpenv elemTy
let tyR = mkArrayTy g rank elemTy m
Expand Down Expand Up @@ -5339,8 +5339,8 @@ and TcExprUndelayedNoType (cenv: cenv) env tpenv synExpr =
let expr, tpenv = TcExprUndelayed cenv (MustEqual overallTy) env tpenv synExpr
expr, overallTy, tpenv

/// Process a leaf construct where the actual type (or an approximation of it such as 'list<_>'
/// or 'array<_>') is already sufficiently pre-known, and the information in the overall type
/// Process a leaf construct where the actual type (or an approximation of it such as '_ list'
/// or '_ array') is already sufficiently pre-known, and the information in the overall type
/// can be eagerly propagated into the actual type (UnifyOverallType), including pre-calculating
/// any type-directed conversion. This must mean that types extracted when processing the expression are not
/// considered in determining any type-directed conversion.
Expand Down
4 changes: 3 additions & 1 deletion src/Compiler/Checking/ConstraintSolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,9 @@ and SolveTypeEqualsType (csenv: ConstraintSolverEnv) ndeep m2 (trace: OptionalTr
if not (typarsAEquiv g aenv tps1 tps2) then localAbortD else
SolveTypeEqualsTypeKeepAbbrevs csenv ndeep m2 trace bodyTy1 bodyTy2

| TType_ucase (uc1, l1), TType_ucase (uc2, l2) when g.unionCaseRefEq uc1 uc2 -> SolveTypeEqualsTypeEqns csenv ndeep m2 trace None l1 l2
| TType_ucase (uc1, l1), TType_ucase (uc2, l2) when g.unionCaseRefEq uc1 uc2 ->
SolveTypeEqualsTypeEqns csenv ndeep m2 trace None l1 l2

| _ -> localAbortD

and SolveTypeEqualsTypeKeepAbbrevs csenv ndeep m2 trace ty1 ty2 =
Expand Down
8 changes: 4 additions & 4 deletions src/Compiler/Checking/MethodCalls.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ let MakeMethInfoCall (amap: ImportMap) m (minfo: MethInfo) minst args staticTyOp
let isProp = false // not necessarily correct, but this is only used post-creflect where this flag is irrelevant
let ilMethodRef = Import.ImportProvidedMethodBaseAsILMethodRef amap m mi
let isConstructor = mi.PUntaint((fun c -> c.IsConstructor), m)
let isStruct = mi.PUntaint((fun c -> c.DeclaringType.IsValueType), m)
let isStruct = mi.PUntaint((fun c -> (nonNull<ProvidedType> c.DeclaringType).IsValueType), m)
let actualTypeInst = [] // GENERIC TYPE PROVIDERS: for generics, we would have something here
let actualMethInst = [] // GENERIC TYPE PROVIDERS: for generics, we would have something here
let ilReturnTys = Option.toList (minfo.GetCompiledReturnType(amap, m, [])) // GENERIC TYPE PROVIDERS: for generics, we would have more here
Expand All @@ -1080,7 +1080,7 @@ let MakeMethInfoCall (amap: ImportMap) m (minfo: MethInfo) minst args staticTyOp
// This imports a provided method, and checks if it is a known compiler intrinsic like "1 + 2"
let TryImportProvidedMethodBaseAsLibraryIntrinsic (amap: Import.ImportMap, m: range, mbase: Tainted<ProvidedMethodBase>) =
let methodName = mbase.PUntaint((fun x -> x.Name), m)
let declaringType = Import.ImportProvidedType amap m (mbase.PApply((fun x -> x.DeclaringType), m))
let declaringType = Import.ImportProvidedType amap m (mbase.PApply((fun x -> nonNull<ProvidedType> x.DeclaringType), m))
match tryTcrefOfAppTy amap.g declaringType with
| ValueSome declaringEntity ->
if not declaringEntity.IsLocalRef && ccuEq declaringEntity.nlr.Ccu amap.g.fslibCcu then
Expand Down Expand Up @@ -2042,7 +2042,7 @@ module ProvidedMethodCalls =
let thisArg, paramVars =
match objArgs with
| [objArg] ->
let erasedThisTy = eraseSystemType (amap, m, mi.PApply((fun mi -> mi.DeclaringType), m))
let erasedThisTy = eraseSystemType (amap, m, mi.PApply((fun mi -> nonNull<ProvidedType> mi.DeclaringType), m))
let thisVar = erasedThisTy.PApply((fun ty -> ty.AsProvidedVar("this")), m)
Some objArg, Array.append [| thisVar |] paramVars
| [] -> None, paramVars
Expand All @@ -2062,7 +2062,7 @@ module ProvidedMethodCalls =
methInfoOpt, expr, exprTy
with
| :? TypeProviderError as tpe ->
let typeName = mi.PUntaint((fun mb -> mb.DeclaringType.FullName), m)
let typeName = mi.PUntaint((fun mb -> (nonNull<ProvidedType> mb.DeclaringType).FullName), m)
let methName = mi.PUntaint((fun mb -> mb.Name), m)
raise( tpe.WithContext(typeName, methName) ) // loses original stack trace
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Checking/MethodOverrides.fs
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ module DispatchSlotChecking =
// dispatch slots are ordered from the derived classes to base
// so we can check the topmost dispatch slot if it is final
match dispatchSlots with
| meth :: _ when meth.IsFinal -> errorR(Error(FSComp.SR.tcCannotOverrideSealedMethod (sprintf "%s::%s" (meth.ApparentEnclosingType.ToString()) meth.LogicalName), m))
| meth :: _ when meth.IsFinal -> errorR(Error(FSComp.SR.tcCannotOverrideSealedMethod((sprintf "%s::%s" (NicePrint.stringOfTy denv meth.ApparentEnclosingType) meth.LogicalName)), m))
| _ -> ()

/// Get the slots of a type that can or must be implemented. This depends
Expand Down
73 changes: 38 additions & 35 deletions src/Compiler/Checking/TypeHierarchy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,44 +41,47 @@ let GetSuperTypeOfType g amap m ty =
let ty = stripTyEqnsAndMeasureEqns g ty
#endif

match metadataOfTy g ty with
let resBeforeNull =
match metadataOfTy g ty with
#if !NO_TYPEPROVIDERS
| ProvidedTypeMetadata info ->
let st = info.ProvidedType
let superOpt = st.PApplyOption((fun st -> match st.BaseType with null -> None | t -> Some t), m)
match superOpt with
| None -> None
| Some super -> Some(ImportProvidedType amap m super)
| ProvidedTypeMetadata info ->
let st = info.ProvidedType
let superOpt = st.PApplyOption((fun st -> match st.BaseType with null -> None | t -> Some t), m)
match superOpt with
| None -> None
| Some super -> Some(ImportProvidedType amap m super)
#endif
| ILTypeMetadata (TILObjectReprData(scoref, _, tdef)) ->
let tinst = argsOfAppTy g ty
match tdef.Extends with
| None -> None
| Some ilTy -> Some (RescopeAndImportILType scoref amap m tinst ilTy)

| FSharpOrArrayOrByrefOrTupleOrExnTypeMetadata ->
if isFSharpObjModelTy g ty || isFSharpExceptionTy g ty then
let tcref = tcrefOfAppTy g ty
Some (instType (mkInstForAppTy g ty) (superOfTycon g tcref.Deref))
elif isArrayTy g ty then
Some g.system_Array_ty
elif isRefTy g ty && not (isObjTy g ty) then
Some g.obj_ty
elif isStructTupleTy g ty then
Some g.system_Value_ty
elif isFSharpStructOrEnumTy g ty then
if isFSharpEnumTy g ty then
Some g.system_Enum_ty
else
| ILTypeMetadata (TILObjectReprData(scoref, _, tdef)) ->
let tinst = argsOfAppTy g ty
match tdef.Extends with
| None -> None
| Some ilTy -> Some (RescopeAndImportILType scoref amap m tinst ilTy)

| FSharpOrArrayOrByrefOrTupleOrExnTypeMetadata ->
if isFSharpObjModelTy g ty || isFSharpExceptionTy g ty then
let tcref = tcrefOfAppTy g ty
Some (instType (mkInstForAppTy g ty) (superOfTycon g tcref.Deref))
elif isArrayTy g ty then
Some g.system_Array_ty
elif isRefTy g ty && not (isObjTy g ty) then
Some g.obj_ty
elif isStructTupleTy g ty then
Some g.system_Value_ty
elif isFSharpStructOrEnumTy g ty then
if isFSharpEnumTy g ty then
Some g.system_Enum_ty
else
Some g.system_Value_ty
elif isStructAnonRecdTy g ty then
Some g.system_Value_ty
elif isStructAnonRecdTy g ty then
Some g.system_Value_ty
elif isAnonRecdTy g ty then
Some g.obj_ty
elif isRecdTy g ty || isUnionTy g ty then
Some g.obj_ty
else
None
elif isAnonRecdTy g ty then
Some g.obj_ty
elif isRecdTy g ty || isUnionTy g ty then
Some g.obj_ty
else
None

resBeforeNull

/// Make a type for System.Collections.Generic.IList<ty>
let mkSystemCollectionsGenericIListTy (g: TcGlobals) ty =
Expand Down
26 changes: 17 additions & 9 deletions src/Compiler/Checking/import.fs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type AssemblyLoader =
/// Get a flag indicating if an assembly is a provided assembly, plus the
/// table of information recording remappings from type names in the provided assembly to type
/// names in the statically linked, embedded assembly.
abstract GetProvidedAssemblyInfo : CompilationThreadToken * range * Tainted<ProvidedAssembly> -> bool * ProvidedAssemblyStaticLinkingMap option
abstract GetProvidedAssemblyInfo : CompilationThreadToken * range * Tainted<ProvidedAssembly MaybeNull> -> bool * ProvidedAssemblyStaticLinkingMap option

/// Record a root for a [<Generate>] type to help guide static linking & type relocation
abstract RecordGeneratedTypeRoot : ProviderGeneratedType -> unit
Expand Down Expand Up @@ -183,16 +183,24 @@ let rec ImportILType (env: ImportMap) m tinst ty =
ImportTyconRefApp env tcref inst

| ILType.Byref ty -> mkByrefTy env.g (ImportILType env m tinst ty)

| ILType.Ptr ILType.Void when env.g.voidptr_tcr.CanDeref -> mkVoidPtrTy env.g

| ILType.Ptr ty -> mkNativePtrTy env.g (ImportILType env m tinst ty)

| ILType.FunctionPointer _ -> env.g.nativeint_ty (* failwith "cannot import this kind of type (ptr, fptr)" *)

| ILType.Modified(_, _, ty) ->
// All custom modifiers are ignored
ImportILType env m tinst ty

| ILType.TypeVar u16 ->
try List.item (int u16) tinst
with _ ->
error(Error(FSComp.SR.impNotEnoughTypeParamsInScopeWhileImporting(), m))
let ty =
try
List.item (int u16) tinst
with _ ->
error(Error(FSComp.SR.impNotEnoughTypeParamsInScopeWhileImporting(), m))
ty

/// Determines if an IL type can be imported as an F# type
let rec CanImportILType (env: ImportMap) m ty =
Expand Down Expand Up @@ -354,15 +362,15 @@ let rec ImportProvidedType (env: ImportMap) (m: range) (* (tinst: TypeInst) *) (

/// Import a provided method reference as an Abstract IL method reference
let ImportProvidedMethodBaseAsILMethodRef (env: ImportMap) (m: range) (mbase: Tainted<ProvidedMethodBase>) =
let tref = GetILTypeRefOfProvidedType (mbase.PApply((fun mbase -> mbase.DeclaringType), m), m)
let tref = GetILTypeRefOfProvidedType (mbase.PApply((fun mbase -> nonNull<ProvidedType> mbase.DeclaringType), m), m)

let mbase =
// Find the formal member corresponding to the called member
match mbase.OfType<ProvidedMethodInfo>() with
| Some minfo when
minfo.PUntaint((fun minfo -> minfo.IsGenericMethod|| minfo.DeclaringType.IsGenericType), m) ->
minfo.PUntaint((fun minfo -> minfo.IsGenericMethod|| (nonNull<ProvidedType> minfo.DeclaringType).IsGenericType), m) ->

let declaringType = minfo.PApply((fun minfo -> minfo.DeclaringType), m)
let declaringType = minfo.PApply((fun minfo -> nonNull<ProvidedType> minfo.DeclaringType), m)

let declaringGenericTypeDefn =
if declaringType.PUntaint((fun t -> t.IsGenericType), m) then
Expand All @@ -381,8 +389,8 @@ let ImportProvidedMethodBaseAsILMethodRef (env: ImportMap) (m: range) (mbase: Ta
error(Error(FSComp.SR.etIncorrectProvidedMethod(DisplayNameOfTypeProvider(minfo.TypeProvider, m), methodName, metadataToken, typeName), m))
| _ ->
match mbase.OfType<ProvidedConstructorInfo>() with
| Some cinfo when cinfo.PUntaint((fun x -> x.DeclaringType.IsGenericType), m) ->
let declaringType = cinfo.PApply((fun x -> x.DeclaringType), m)
| Some cinfo when cinfo.PUntaint((fun x -> (nonNull<ProvidedType> x.DeclaringType).IsGenericType), m) ->
let declaringType = cinfo.PApply((fun x -> nonNull<ProvidedType> x.DeclaringType), m)
let declaringGenericTypeDefn = declaringType.PApply((fun x -> x.GetGenericTypeDefinition()), m)

// We have to find the uninstantiated formal signature corresponding to this instantiated constructor.
Expand Down
Loading

0 comments on commit 8c91d38

Please sign in to comment.