Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf5fccbd

Browse files
dsymeKevinRansom
authored andcommitted
Fix 3016: Decode syntactic types using FSharpFunc, Tuple, ValueTuple (#3283)
* decode syntactic types using FSharpFunc, Tuple, ValueTuple* add test* update tests* update tests
1 parent0eb40a2 commitf5fccbd

File tree

7 files changed

+112
-65
lines changed

7 files changed

+112
-65
lines changed

‎src/fsharp/TcGlobals.fs‎

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -673,54 +673,52 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d
673673
letaddFieldNeverAttrs(fdef:ILFieldDef)={fdefwith CustomAttrs= addNeverAttrs fdef.CustomAttrs}
674674
letmkDebuggerTypeProxyAttribute(ty:ILType)= mkILCustomAttribute ilg(findSysILTypeRef tname_DebuggerTypeProxyAttribute,[ilg.typ_Type],[ILAttribElem.TypeRef(Some ty.TypeRef)],[])
675675

676+
letentries1=
677+
[|"Int32", v_int_tcr
678+
"IntPtr", v_nativeint_tcr
679+
"UIntPtr", v_unativeint_tcr
680+
"Int16", v_int16_tcr
681+
"Int64", v_int64_tcr
682+
"UInt16", v_uint16_tcr
683+
"UInt32", v_uint32_tcr
684+
"UInt64", v_uint64_tcr
685+
"SByte", v_sbyte_tcr
686+
"Decimal", v_decimal_tcr
687+
"Byte", v_byte_tcr
688+
"Boolean", v_bool_tcr
689+
"String", v_string_tcr
690+
"Object", v_obj_tcr
691+
"Exception", v_exn_tcr
692+
"Char", v_char_tcr
693+
"Double", v_float_tcr
694+
"Single", v_float32_tcr|]
695+
|> Array.map(fun(nm,tcr)->
696+
letty= mkNonGenericTy tcr
697+
nm, findSysTyconRef sys nm,(fun _-> ty))
698+
699+
letentries2=
700+
[|
701+
"FSharpFunc`2", v_fastFunc_tcr,(fun tinst-> mkFunTy(List.item0 tinst)(List.item1 tinst))
702+
"Tuple`2", v_ref_tuple2_tcr, decodeTupleTy tupInfoRef
703+
"Tuple`3", v_ref_tuple3_tcr, decodeTupleTy tupInfoRef
704+
"Tuple`4", v_ref_tuple4_tcr, decodeTupleTy tupInfoRef
705+
"Tuple`5", v_ref_tuple5_tcr, decodeTupleTy tupInfoRef
706+
"Tuple`6", v_ref_tuple6_tcr, decodeTupleTy tupInfoRef
707+
"Tuple`7", v_ref_tuple7_tcr, decodeTupleTy tupInfoRef
708+
"Tuple`8", v_ref_tuple8_tcr, decodeTupleTy tupInfoRef
709+
"ValueTuple`2", v_struct_tuple2_tcr, decodeTupleTy tupInfoStruct
710+
"ValueTuple`3", v_struct_tuple3_tcr, decodeTupleTy tupInfoStruct
711+
"ValueTuple`4", v_struct_tuple4_tcr, decodeTupleTy tupInfoStruct
712+
"ValueTuple`5", v_struct_tuple5_tcr, decodeTupleTy tupInfoStruct
713+
"ValueTuple`6", v_struct_tuple6_tcr, decodeTupleTy tupInfoStruct
714+
"ValueTuple`7", v_struct_tuple7_tcr, decodeTupleTy tupInfoStruct
715+
"ValueTuple`8", v_struct_tuple8_tcr, decodeTupleTy tupInfoStruct|]
716+
676717
// Build a map that uses the "canonical" F# type names and TyconRef's for these
677718
// in preference to the .NET type names. Doing this normalization is a fairly performance critical
678719
// piece of code as it is frequently invoked in the process of converting .NET metadata to F# internal
679720
// compiler data structures (see import.fs).
680-
letbetterTyconRefMap=
681-
begin
682-
letentries1=
683-
[|"Int32", v_int_tcr
684-
"IntPtr", v_nativeint_tcr
685-
"UIntPtr", v_unativeint_tcr
686-
"Int16", v_int16_tcr
687-
"Int64", v_int64_tcr
688-
"UInt16", v_uint16_tcr
689-
"UInt32", v_uint32_tcr
690-
"UInt64", v_uint64_tcr
691-
"SByte", v_sbyte_tcr
692-
"Decimal", v_decimal_tcr
693-
"Byte", v_byte_tcr
694-
"Boolean", v_bool_tcr
695-
"String", v_string_tcr
696-
"Object", v_obj_tcr
697-
"Exception", v_exn_tcr
698-
"Char", v_char_tcr
699-
"Double", v_float_tcr
700-
"Single", v_float32_tcr|]
701-
|> Array.map(fun(nm,tcr)->
702-
letty= mkNonGenericTy tcr
703-
nm, findSysTyconRef sys nm,(fun _-> ty))
704-
705-
letentries2=
706-
[|
707-
"FSharpFunc`2", v_fastFunc_tcr,(fun tinst-> mkFunTy(List.item0 tinst)(List.item1 tinst))
708-
"Tuple`2", v_ref_tuple2_tcr, decodeTupleTy tupInfoRef
709-
"Tuple`3", v_ref_tuple3_tcr, decodeTupleTy tupInfoRef
710-
"Tuple`4", v_ref_tuple4_tcr, decodeTupleTy tupInfoRef
711-
"Tuple`5", v_ref_tuple5_tcr, decodeTupleTy tupInfoRef
712-
"Tuple`6", v_ref_tuple6_tcr, decodeTupleTy tupInfoRef
713-
"Tuple`7", v_ref_tuple7_tcr, decodeTupleTy tupInfoRef
714-
"Tuple`8", v_ref_tuple8_tcr, decodeTupleTy tupInfoRef
715-
"ValueTuple`2", v_struct_tuple2_tcr, decodeTupleTy tupInfoStruct
716-
"ValueTuple`3", v_struct_tuple3_tcr, decodeTupleTy tupInfoStruct
717-
"ValueTuple`4", v_struct_tuple4_tcr, decodeTupleTy tupInfoStruct
718-
"ValueTuple`5", v_struct_tuple5_tcr, decodeTupleTy tupInfoStruct
719-
"ValueTuple`6", v_struct_tuple6_tcr, decodeTupleTy tupInfoStruct
720-
"ValueTuple`7", v_struct_tuple7_tcr, decodeTupleTy tupInfoStruct
721-
"ValueTuple`8", v_struct_tuple8_tcr, decodeTupleTy tupInfoStruct|]
722-
723-
letentries= Array.append entries1 entries2
721+
letbuildTyconMapper(entries:(string* TyconRef* _)[])=
724722
if compilingFslibthen
725723
// This map is for use when building FSharp.Core.dll. The backing Tycon's may not yet exist for
726724
// the TyconRef's we have in our hands, hence we can't dereference them to find their stamps.
@@ -759,8 +757,10 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d
759757
letkey= tcref2.Stamp
760758
if dict.ContainsKey keythen Some(dict.[key] tinst)
761759
else None)
762-
end
763-
760+
761+
letbetterTyconRefMapper= buildTyconMapper(Array.append entries1 entries2)
762+
763+
letdecodeTyconRefMapper= buildTyconMapper entries2
764764

765765
overridex.ToString()="<TcGlobals>"
766766
member__.ilg=ilg
@@ -1052,7 +1052,8 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d
10521052
member valattrib_SecuritySafeCriticalAttribute= findSysAttrib"System.Security.SecuritySafeCriticalAttribute"
10531053
member valattrib_ComponentModelEditorBrowsableAttribute= findSysAttrib"System.ComponentModel.EditorBrowsableAttribute"
10541054

1055-
member__.better_tcref_map= betterTyconRefMap
1055+
member__.betterTyconRefMap= betterTyconRefMapper
1056+
member__.decodeTyconRefMap= decodeTyconRefMapper
10561057
member__.new_decimal_info= v_new_decimal_info
10571058
member__.seq_info= v_seq_info
10581059
member valseq_vref=(ValRefForIntrinsic v_seq_info)

‎src/fsharp/TypeChecker.fs‎

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4858,31 +4858,44 @@ and TcProvidedTypeApp cenv env tpenv tcref args m =
48584858
/// Note that the generic type may be a nested generic type List<T>.ListEnumerator<U>.
48594859
/// In this case, 'args' is only the instantiation of the suffix type arguments, and pathTypeArgs gives
48604860
/// the prefix of type arguments.
4861-
and TcTypeApp cenv newOk checkCxs occ env tpenv m tcref pathTypeArgs (args: SynType list) =
4861+
and TcTypeApp cenv newOk checkCxs occ env tpenv m tcref pathTypeArgs (synArgTys: SynType list) =
48624862
CheckTyconAccessible cenv.amap m env.eAccessRights tcref |> ignore
48634863
CheckEntityAttributes cenv.g tcref m |> CommitOperationResult
48644864

48654865
#if EXTENSIONTYPING
48664866
// Provided types are (currently) always non-generic. Their names may include mangled
48674867
// static parameters, which are passed by the provider.
4868-
if tcref.Deref.IsProvided then TcProvidedTypeApp cenv env tpenv tcrefargs m else
4868+
if tcref.Deref.IsProvided then TcProvidedTypeApp cenv env tpenv tcrefsynArgTys m else
48694869
#endif
48704870

48714871
let tps,_,tinst,_ = infoOfTyconRef m tcref
4872+
48724873
// If we're not checking constraints, i.e. when we first assert the super/interfaces of a type definition, then just
48734874
// clear the constraint lists of the freshly generated type variables. A little ugly but fairly localized.
48744875
if checkCxs = NoCheckCxs then tps |> List.iter (fun tp -> tp.typar_constraints <- [])
4875-
if tinst.Length <> pathTypeArgs.Length + args.Length then
4876-
error (TyconBadArgs(env.DisplayEnv,tcref,pathTypeArgs.Length + args.Length,m))
4877-
let args',tpenv =
4876+
if tinst.Length <> pathTypeArgs.Length + synArgTys.Length then
4877+
error (TyconBadArgs(env.DisplayEnv,tcref,pathTypeArgs.Length + synArgTys.Length,m))
4878+
4879+
let argTys,tpenv =
48784880
// Get the suffix of typars
4879-
let tpsForArgs = List.drop (tps.Length -args.Length) tps
4881+
let tpsForArgs = List.drop (tps.Length -synArgTys.Length) tps
48804882
let kindsForArgs = tpsForArgs |> List.map (fun tp -> tp.Kind)
4881-
TcTypesOrMeasures (Some kindsForArgs) cenv newOk checkCxs occ env tpenv args m
4882-
let args' = pathTypeArgs @ args'
4883+
TcTypesOrMeasures (Some kindsForArgs) cenv newOk checkCxs occ env tpenv synArgTys m
4884+
4885+
// Add the types of the enclosing class for a nested type
4886+
let actualArgTys = pathTypeArgs @ argTys
4887+
48834888
if checkCxs = CheckCxs then
4884-
List.iter2 (UnifyTypes cenv env m) tinst args'
4885-
mkAppTy tcref args', tpenv
4889+
List.iter2 (UnifyTypes cenv env m) tinst actualArgTys
4890+
4891+
// Try to decode System.Tuple --> F~ tuple types etc.
4892+
let ty =
4893+
let decode = if cenv.g.compilingFslib then None else cenv.g.decodeTyconRefMap tcref actualArgTys
4894+
match decode with
4895+
| Some res -> res
4896+
| None -> mkAppTy tcref actualArgTys
4897+
4898+
ty, tpenv
48864899

48874900
and TcTypeOrMeasureAndRecover optKind cenv newOk checkCxs occ env tpenv ty =
48884901
try TcTypeOrMeasure optKind cenv newOk checkCxs occ env tpenv ty

‎src/fsharp/import.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ let CanImportILTypeRef (env:ImportMap) m (tref:ILTypeRef) =
151151
/// Prefer the F# abbreviation for some built-in types, e.g. 'string' rather than
152152
/// 'System.String', since we prefer the F# abbreviation to the .NET equivalents.
153153
letImportTyconRefApp(env:ImportMap)tcref tyargs=
154-
match env.g.better_tcref_map tcref tyargswith
154+
match env.g.betterTyconRefMap tcref tyargswith
155155
| Some res-> res
156156
| None-> TType_app(tcref,tyargs)
157157

‎tests/fsharp/tests.fs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,14 @@ module TypecheckTests =
16711671
#endif
16721672

16731673
#if!FSHARP_SUITE_DRIVES_CORECLR_TESTS
1674+
[<Test>]
1675+
let``sigs pos27``()=
1676+
letcfg= testConfig"typecheck/sigs"
1677+
fsc cfg"%s --target:exe -o:pos27.exe" cfg.fsc_flags["pos27.fs"]
1678+
copy_y cfg(cfg.FSCBinPath++"System.ValueTuple.dll")("."++"System.ValueTuple.dll")
1679+
1680+
peverify cfg"pos27.exe"
1681+
16741682
[<Test>]
16751683
let``sigs pos26``()=
16761684
letcfg= testConfig"typecheck/sigs"

‎tests/fsharp/typecheck/sigs/neg23.bsl‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11

2-
neg23.fs(9,21,9,24): typecheck error FS0438: Duplicate method. The method 'Foo' has the same nameand signature as another methodin type 'DuplicateOverloadUpToErasure1.SomeClass' once tuples, functions, units of measureand/or provided types are erased.
2+
neg23.fs(9,21,9,24): typecheck error FS0438: Duplicate method. The method 'Foo' has the same nameand signature as another methodin type 'DuplicateOverloadUpToErasure1.SomeClass'.
33

4-
neg23.fs(7,21,7,24): typecheck error FS0438: Duplicate method. The method 'Foo' has the same nameand signature as another methodin type 'DuplicateOverloadUpToErasure1.SomeClass' once tuples, functions, units of measureand/or provided types are erased.
4+
neg23.fs(7,21,7,24): typecheck error FS0438: Duplicate method. The method 'Foo' has the same nameand signature as another methodin type 'DuplicateOverloadUpToErasure1.SomeClass'.
55

6-
neg23.fs(19,21,19,24): typecheck error FS0438: Duplicate method. The method 'Foo' has the same nameand signature as another methodin type 'DuplicateOverloadUpToErasure2.SomeClass' once tuples, functions, units of measureand/or provided types are erased.
6+
neg23.fs(19,21,19,24): typecheck error FS0438: Duplicate method. The method 'Foo' has the same nameand signature as another methodin type 'DuplicateOverloadUpToErasure2.SomeClass'.
77

8-
neg23.fs(17,21,17,24): typecheck error FS0438: Duplicate method. The method 'Foo' has the same nameand signature as another methodin type 'DuplicateOverloadUpToErasure2.SomeClass' once tuples, functions, units of measureand/or provided types are erased.
8+
neg23.fs(17,21,17,24): typecheck error FS0438: Duplicate method. The method 'Foo' has the same nameand signature as another methodin type 'DuplicateOverloadUpToErasure2.SomeClass'.
99

10-
neg23.fs(28,21,28,24): typecheck error FS0438: Duplicate method. The method 'Foo' has the same nameand signature as another methodin type 'DuplicateOverloadUpToErasure3.SomeClass' once tuples, functions, units of measureand/or provided types are erased.
10+
neg23.fs(28,21,28,24): typecheck error FS0438: Duplicate method. The method 'Foo' has the same nameand signature as another methodin type 'DuplicateOverloadUpToErasure3.SomeClass'.
1111

12-
neg23.fs(26,21,26,24): typecheck error FS0438: Duplicate method. The method 'Foo' has the same nameand signature as another methodin type 'DuplicateOverloadUpToErasure3.SomeClass' once tuples, functions, units of measureand/or provided types are erased.
12+
neg23.fs(26,21,26,24): typecheck error FS0438: Duplicate method. The method 'Foo' has the same nameand signature as another methodin type 'DuplicateOverloadUpToErasure3.SomeClass'.
1313

1414
neg23.fs(55,21,55,24): typecheck error FS0438: Duplicate method. The method 'Foo' has the same nameand signature as another methodin type 'DuplicateOverloadUpToErasure6.SomeClass' once tuples, functions, units of measureand/or provided types are erased.
1515

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
modulePos27
2+
3+
moduleTUple=
4+
letx1:System.Tuple<int>= System.Tuple.Create(1)
5+
letx2:System.Tuple<int,int>= System.Tuple.Create(1,2)
6+
letx3:System.Tuple<int,int,int>= System.Tuple.Create(1,2,3)
7+
letx4:System.Tuple<int,int,int,int>= System.Tuple.Create(1,2,3,4)
8+
letx5:System.Tuple<int,int,int,int,int>= System.Tuple.Create(1,2,3,4,5)
9+
letx6:System.Tuple<int,int,int,int,int,int>= System.Tuple.Create(1,2,3,4,5,6)
10+
letx7:System.Tuple<int,int,int,int,int,int,int>= System.Tuple.Create(1,2,3,4,5,6,7)
11+
letx9:System.Tuple<int,int,int,int,int,int,int,System.Tuple<int>>= System.Tuple.Create(1,2,3,4,5,6,7,8)
12+
13+
moduleValueTuple=
14+
letx1:System.ValueTuple<int>= System.ValueTuple.Create(1)
15+
letx2:System.ValueTuple<int,int>= System.ValueTuple.Create(1,2)
16+
letx3:System.ValueTuple<int,int,int>= System.ValueTuple.Create(1,2,3)
17+
letx4:System.ValueTuple<int,int,int,int>= System.ValueTuple.Create(1,2,3,4)
18+
letx5:System.ValueTuple<int,int,int,int,int>= System.ValueTuple.Create(1,2,3,4,5)
19+
letx6:System.ValueTuple<int,int,int,int,int,int>= System.ValueTuple.Create(1,2,3,4,5,6)
20+
letx7:System.ValueTuple<int,int,int,int,int,int,int>= System.ValueTuple.Create(1,2,3,4,5,6,7)
21+
letx9:System.ValueTuple<int,int,int,int,int,int,int,System.ValueTuple<int>>= System.ValueTuple.Create(1,2,3,4,5,6,7,8)
22+
23+
moduleFSharpFunc=
24+
letx1:FSharpFunc<int,int>=(fun x-> x+1)
25+
letx2:FSharpFunc<int,FSharpFunc<int,int>>=(fun x y-> x+1+ y)

‎tests/fsharpqa/Source/Conformance/DeclarationElements/MemberDefinitions/OverloadingMembers/E_InferredTypeNotUnique01.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// #Regression #Conformance #DeclarationElements #MemberDefinitions #Overloading
22
// Regression test for FSharp1.0:3762 - Using FastFunc explicitly is not differentiate from function types, thus causing compiler to create bad method tables, maybe other problems
3-
//<Expects span="(7,17-7,20)" status="error">Duplicate method\. The method 'Foo' has the same name and signature as another method in type 'SomeClass' once tuples, functions, units of measure and/or provided types are erased\.</Expects>
3+
//<Expects span="(7,17-7,20)" status="error">Duplicate method\. The method 'Foo' has the same name and signature as another method in type 'SomeClass'\.</Expects>
44
// Note: as of Beta2, FastFunc became FSharpFunc
55
typeSomeClass()=
66

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp