Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement MVP part of const generics for CoreCLR #89636

Closed
wants to merge 86 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
4e55d7c
Parse const generic parameters
hez2010 Jul 20, 2023
72fcce6
Fixes to parsing and add basic binary layout support
hez2010 Jul 21, 2023
05034f0
More fixes to naming
hez2010 Jul 21, 2023
b7cf656
Complete assembly emitter
hez2010 Jul 22, 2023
19d1702
Emit const generics for method
hez2010 Jul 22, 2023
7713175
Add ildasm support for const generics declaration
hez2010 Jul 22, 2023
eb021d9
Introduce meta model v2.1
hez2010 Jul 22, 2023
79f5bc3
Add parsing and emitting support for instantiation and calling
hez2010 Jul 22, 2023
c29b87d
Move opcode def upper
hez2010 Jul 22, 2023
3d2835c
Merge branch 'dotnet:main' into feature/const-generics
hez2010 Jul 22, 2023
a9f166a
Implement ldtarg and ldtarg.s in parser, emitter and disasmer
hez2010 Jul 22, 2023
b18f20e
Support using type parameter index directly in parser
hez2010 Jul 22, 2023
4b7d14f
Remove ldtc.* and rename ldtarg to ldctarg
hez2010 Jul 23, 2023
084651c
Remove unused ELEMENT_TYPE_CONSTTYPE
hez2010 Jul 23, 2023
8ebd325
Fix a bug where CorSigUncompressConstTypeArgData shifts dataPtr by mi…
hez2010 Jul 23, 2023
15d0a2c
Fix ldctarg def
hez2010 Jul 23, 2023
a34f4bf
Fix the missing data len addition to typePtr
hez2010 Jul 23, 2023
c51378d
Bump metamodel version to v3.0 and add fallback schema for v2.0
hez2010 Jul 23, 2023
e247c0e
Load assembly in VM
hez2010 Jul 23, 2023
14de598
Back-compat fixes and add some helpers for const generics
hez2010 Jul 24, 2023
c5dd614
WIP: ConstValueEEType and MethodTable changes
hez2010 Jul 24, 2023
3d58e01
Remove redundant szPrefix
hez2010 Jul 24, 2023
f3cb8ab
Add the missing `const` in ildasm
hez2010 Jul 25, 2023
97a7b06
Add isConst to CorTypeInfo
hez2010 Jul 25, 2023
6eee670
Minor fixes
hez2010 Jul 25, 2023
5835cf8
WIP: MethodTableBuilder and ClassLoader support for ConstValueType
hez2010 Jul 26, 2023
6d3c1f3
WIP: TypeLoader for const value
hez2010 Jul 26, 2023
87d8006
Complete class loader implementation
hez2010 Jul 26, 2023
5dbda0a
Use AppendTypeDef for const generic variable typestring
hez2010 Jul 26, 2023
bb9a907
Handle CVAR and MCVAR in GetTypeHandleThrowing
hez2010 Jul 26, 2023
5c5ad11
Updates to JIT-EE interfaces
hez2010 Jul 26, 2023
ccdd3a8
Implement type lookup for ELEMENT_TYPE_CTARG
hez2010 Jul 27, 2023
d663329
Add support for hashing const value type
hez2010 Jul 27, 2023
4225bf1
Change the way of encoding ldctarg, and remove ldctarg.s
hez2010 Jul 27, 2023
71a0664
Use ldtoken instead of ldctarg
hez2010 Jul 27, 2023
faba1ec
Complete!
hez2010 Jul 27, 2023
6ee5cf5
Fix data gets truncated due to cast.
hez2010 Jul 27, 2023
6a45bb2
Add a NYI note around type loader.
hez2010 Jul 27, 2023
306b09a
Fixes for type resolving on (M)CVAR
hez2010 Jul 27, 2023
167bff9
Implement superpmi
hez2010 Jul 28, 2023
179cb05
Implement const value lookup
hez2010 Jul 28, 2023
b891897
Implement support for const generic virtual methods
hez2010 Jul 28, 2023
9137b04
Remove ELEMENT_TYPE_{M}CVAR
hez2010 Jul 28, 2023
6639399
Clean up
hez2010 Jul 28, 2023
9db89cf
Add missing superpmi implementation
hez2010 Jul 28, 2023
f7c68cf
Fix the incorrect type mapping on uint64_t
hez2010 Jul 28, 2023
8709dd8
Add NYI for JIT-EE interfaces in managed type system.
hez2010 Jul 28, 2023
1bebc8d
Initialize pResolvedToken correctly
hez2010 Jul 28, 2023
6f9db7c
Use uint64_t for all const values
hez2010 Jul 28, 2023
d1a4652
Clean up unmeaningful changes
hez2010 Jul 28, 2023
4b55eb0
Merge branch 'main' into feature/const-generics
hez2010 Jul 29, 2023
21d262f
Parsing bytearray and string
hez2010 Jul 30, 2023
d5d18d6
Char size fixes
hez2010 Jul 30, 2023
49e95ab
Use CorInfoType in jitinterface
hez2010 Jul 30, 2023
97a60aa
Initialize CORINFO_RESOLVED_TOKEN
hez2010 Jul 30, 2023
e554aa5
Fix an assert
hez2010 Jul 30, 2023
30b0681
Bring back CORINFO_TYPE_CTARG
hez2010 Jul 30, 2023
e75a400
Fix hash function for const value
hez2010 Jul 30, 2023
2a8ae6d
Handle default case in appendStrBlob
hez2010 Jul 30, 2023
6d9b91e
Use uint64_t instead of DWORDLONG
hez2010 Jul 30, 2023
8a6fbf5
Fix formatting
hez2010 Jul 30, 2023
9500e1b
Switch back to DWORDLONG and use PRIX64
hez2010 Jul 30, 2023
fe1f48b
DWORDLONG leftovers
hez2010 Jul 30, 2023
b5ec226
Minor fixes
hez2010 Jul 31, 2023
424e9a2
Use bison for ilasm parser generator
hez2010 Jul 31, 2023
3bf3d70
Fix asmparse build failure
hez2010 Jul 31, 2023
5a018b2
Fix the missing fallback path to GenericParamRec
hez2010 Jul 31, 2023
80ff093
Merge branch 'dotnet:main' into feature/const-generics
hez2010 Jul 31, 2023
af861b4
Add support for type validation
hez2010 Aug 2, 2023
9b76911
Implement typestring for const type parameter
hez2010 Aug 2, 2023
9a90c35
Merge branch 'dotnet:main' into feature/const-generics
hez2010 Aug 2, 2023
20db638
Fix build failure
hez2010 Aug 2, 2023
1d6c3f8
Fix format
hez2010 Aug 2, 2023
2e10415
Fix generics on const type parameter parsing
hez2010 Aug 3, 2023
7dc3c45
Use byacc for ilasm parser generator
hez2010 Aug 3, 2023
a2d4d3f
Parse constraints for const type parameter
hez2010 Aug 4, 2023
edab29d
Correctly format method name
hez2010 Aug 4, 2023
902e196
Reuse "literal" keyword in IL and get rid of "const"
hez2010 Aug 6, 2023
b8bee87
Merge branch 'main' into feature/const-generics
hez2010 Aug 21, 2023
c8a2702
Generate new JIT-EE interface
hez2010 Aug 21, 2023
4bd7a65
Fix some comments
hez2010 Aug 21, 2023
9a7013f
Use TypeHandle for ConstValueType
hez2010 Aug 22, 2023
a70dfdc
Use TypeHandle in class loader
hez2010 Aug 22, 2023
7044cc7
Support const generic type to be used in a field
hez2010 Aug 23, 2023
c8a2ccf
Merge branch 'main' into feature/const-generics
hez2010 Sep 19, 2023
5d3da96
Emit type of type parameter in generic constraint table
hez2010 Sep 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/coreclr/ilasm/asmparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ class AsmParse : public ErrorReporter
friend int ProcessEOF();
friend unsigned __int8* skipType(unsigned __int8* ptr, BOOL fFixupType);
friend void FixupConstraints();
friend void ResolveTyParList(TyParList* list);

Assembler* assem; // This does most of the semantic processing
bool success; // overall success of the compilation
Expand Down
56 changes: 53 additions & 3 deletions src/coreclr/ilasm/asmparse.y
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,14 @@
/* nonTerminals */
%type <string> dottedName id methodName atOpt slashedName
%type <labels> labels
%type <int32> callConv callKind int32 customHead customHeadWithOwner vtfixupAttr paramAttr ddItemCount variantType repeatOpt truefalse typarAttrib typarAttribs
%type <int32> callConv callKind int32 customHead customHeadWithOwner vtfixupAttr paramAttr ddItemCount variantType repeatOpt truefalse typarAttrib typarAttribs conTyparAttrib conTyparAttribs
%type <int32> iidParamIndex genArity genArityNotEmpty
%type <float64> float64
%type <int64> int64
%type <binstr> sigArgs0 sigArgs1 sigArg type bound bounds1 bytes hexbytes nativeType marshalBlob initOpt compQstring caValue
%type <binstr> marshalClause
%type <binstr> fieldInit serInit fieldSerInit
%type <binstr> constTypeArg
%type <binstr> f32seq f64seq i8seq i16seq i32seq i64seq boolSeq sqstringSeq classSeq objSeq
%type <binstr> simpleType
%type <binstr> tyArgs0 tyArgs1 tyArgs2 typeList typeListNotEmpty tyBound
Expand Down Expand Up @@ -479,7 +480,7 @@ typeListNotEmpty : typeSpec { $$ = new BinStr();
;

typarsClause : /* EMPTY */ { $$ = NULL; PASM->m_TyParList = NULL;}
| '<' typars '>' { $$ = $2; PASM->m_TyParList = $2;}
| '<' typars '>' { PASM->m_TyParList = $2; ResolveTyParList(PASM->m_TyParList); $$ = PASM->m_TyParList; }
;

typarAttrib : '+' { $$ = gpCovariant; }
Expand All @@ -495,7 +496,16 @@ typarAttribs : /* EMPTY */ { $$ = 0; }
| typarAttrib typarAttribs { $$ = $1 | $2; }
;

typars : typarAttribs tyBound dottedName typarsRest {$$ = new TyParList($1, $2, $3, $4);}
conTyparAttrib : FLAGS_ '(' int32 ')' { $$ = (CorGenericParamAttr)$3; }
;

conTyparAttribs : /* EMPTY */ { $$ = 0; }
| conTyparAttrib conTyparAttribs { $$ = $1 | $2; }
;

typars : LITERAL_ conTyparAttribs type tyBound dottedName typarsRest {$$ = new TyParList($2, $3, $4, $5, $6); }
| LITERAL_ conTyparAttribs type dottedName typarsRest {$$ = new TyParList($2, $3, NULL, $4, $5); }
| typarAttribs tyBound dottedName typarsRest {$$ = new TyParList($1, $2, $3, $4);}
| typarAttribs dottedName typarsRest {$$ = new TyParList($1, NULL, $2, $3);}
;

Expand Down Expand Up @@ -1254,6 +1264,45 @@ serInit : fieldSerInit { $$ = $1; }
$$->insertInt8(ELEMENT_TYPE_SZARRAY); }
;

constTypeArg : FLOAT32_ '(' float64 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_R4);
float f = (float)(*$3);
$$->appendInt32(*((__int32*)&f)); delete $3; }
| FLOAT64_ '(' float64 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_R8);
$$->appendInt64((__int64 *)$3); delete $3; }
| FLOAT32_ '(' int32 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_R4);
$$->appendInt32($3); }
| FLOAT64_ '(' int64 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_R8);
$$->appendInt64((__int64 *)$3); delete $3; }
| INT64_ '(' int64 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_I8);
$$->appendInt64((__int64 *)$3); delete $3; }
| INT32_ '(' int32 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_I4);
$$->appendInt32($3); }
| INT16_ '(' int32 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_I2);
$$->appendInt16($3); }
| INT8_ '(' int32 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_I1);
$$->appendInt8($3); }
| UNSIGNED_ INT64_ '(' int64 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U8);
$$->appendInt64((__int64 *)$4); delete $4; }
| UNSIGNED_ INT32_ '(' int32 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U4);
$$->appendInt32($4); }
| UNSIGNED_ INT16_ '(' int32 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U2);
$$->appendInt16($4); }
| UNSIGNED_ INT8_ '(' int32 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U1);
$$->appendInt8($4); }
| UINT64_ '(' int64 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U8);
$$->appendInt64((__int64 *)$3); delete $3; }
| UINT32_ '(' int32 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U4);
$$->appendInt32($3); }
| UINT16_ '(' int32 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U2);
$$->appendInt16($3); }
| UINT8_ '(' int32 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U1);
$$->appendInt8($3); }
| CHAR_ '(' int32 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_CHAR);
$$->appendInt16($3); }
| BOOL_ '(' truefalse ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_BOOLEAN);
$$->appendInt8($3);}
;


f32seq : /* EMPTY */ { $$ = new BinStr(); }
| f32seq float64 { $$ = $1;
Expand Down Expand Up @@ -1677,6 +1726,7 @@ type : CLASS_ className { if($2 == PASM->m
| OBJECT_ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_OBJECT); }
| VALUE_ CLASS_ className { $$ = parser->MakeTypeClass(ELEMENT_TYPE_VALUETYPE, $3); }
| VALUETYPE_ className { $$ = parser->MakeTypeClass(ELEMENT_TYPE_VALUETYPE, $2); }
| constTypeArg { $$ = $1; $$->insertInt8(ELEMENT_TYPE_CTARG); }
| type '[' ']' { $$ = $1; $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
| type '[' bounds1 ']' { $$ = parser->MakeTypeArray(ELEMENT_TYPE_ARRAY, $1, $3); }
| type '&' { $$ = $1; $$->insertInt8(ELEMENT_TYPE_BYREF); }
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/ilasm/assem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ BOOL Assembler::EmitMethod(Method *pMethod)
mdGenericParam tkGP = mdTokenNil;
for(i = 0; i < pMethod->m_NumTyPars; i++)
{
if (FAILED(m_pEmitter->DefineGenericParam(MethodToken, i, pMethod->m_TyPars[i].Attrs(), pMethod->m_TyPars[i].Name(), 0, &tkNil, &tkGP)))
if (FAILED(m_pEmitter->DefineGenericParam(MethodToken, i, pMethod->m_TyPars[i].Attrs(), pMethod->m_TyPars[i].Name(), pMethod->m_TyPars[i].Type(), &tkNil, &tkGP)))
{
report->error("Unable to define generic param: %s'\n", pMethod->m_TyPars[i].Name());
}
Expand Down Expand Up @@ -1118,7 +1118,7 @@ BOOL Assembler::EmitClass(Class *pClass)
mdGenericParam tkGP = mdTokenNil;
for(i = 0; i < pClass->m_NumTyPars; i++)
{
if (FAILED(m_pEmitter->DefineGenericParam(pClass->m_cl, i, pClass->m_TyPars[i].Attrs(), pClass->m_TyPars[i].Name(), 0, &tkNil, &tkGP)))
if (FAILED(m_pEmitter->DefineGenericParam(pClass->m_cl, i, pClass->m_TyPars[i].Attrs(), pClass->m_TyPars[i].Name(), pClass->m_TyPars[i].Type(), &tkNil, &tkGP)))
{
report->error("Unable to define generic param: %s'\n", pClass->m_TyPars[i].Name());
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/ilasm/assembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ class Assembler {
void SetStdMapping(BOOL val = TRUE) { m_fStdMapping = val; };

//--------------------------------------------------------------------------------
BOOL isShort(unsigned instr) { return ((OpcodeInfo[instr].Type & 16) != 0); };
BOOL isShort(unsigned instr) { return ((OpcodeInfo[instr].Type & opcode_format_t::ShortInline) != 0); };
unsigned ShortOf(unsigned opcode);
void SetErrorReporter(ErrorReporter* aReport) { report = aReport; if(m_pManifest) m_pManifest->SetErrorReporter(aReport); }

Expand Down
24 changes: 19 additions & 5 deletions src/coreclr/ilasm/grammar_after.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static Keywords keywords[] = {
#define InlineR INSTR_R
#define ShortInlineR INSTR_R
#define InlineBrTarget INSTR_BRTARGET
#define ShortInlineBrTarget INSTR_BRTARGET
#define ShortInlineBrTarget INSTR_BRTARGET
#define InlineMethod INSTR_METHOD
#define InlineField INSTR_FIELD
#define InlineType INSTR_TYPE
Expand Down Expand Up @@ -1329,7 +1329,6 @@ static void corEmitInt(BinStr* buff, unsigned data)
buff->remove(5 - cnt);
}


/**************************************************************************/
/* move 'ptr past the exactly one type description */

Expand Down Expand Up @@ -1360,11 +1359,13 @@ unsigned __int8* skipType(unsigned __int8* ptr, BOOL fFixupType)
/* do nothing */
break;

case ELEMENT_TYPE_VALUETYPE :
case ELEMENT_TYPE_VALUETYPE :
case ELEMENT_TYPE_CLASS :
ptr += CorSigUncompressToken(ptr, &tk);
break;

case ELEMENT_TYPE_CTARG :
ptr += CorSigUncompressConstTypeArgData((PCCOR_SIGNATURE&) ptr); // const type argument
break;
case ELEMENT_TYPE_CMOD_REQD :
case ELEMENT_TYPE_CMOD_OPT :
ptr += CorSigUncompressToken(ptr, &tk);
Expand Down Expand Up @@ -1530,7 +1531,6 @@ unsigned __int8* skipType(unsigned __int8* ptr, BOOL fFixupType)
}
}
break;

default:
case ELEMENT_TYPE_END :
_ASSERTE(!"Unknown Type");
Expand All @@ -1557,6 +1557,20 @@ void FixupTyPars(BinStr* pbstype)
FixupTyPars((PCOR_SIGNATURE)(pbstype->ptr()),(ULONG)(pbstype->length()));
}
/**************************************************************************/
void ResolveTyParList(TyParList* list)
{
TyParList* cur = list;
while (cur != NULL)
{
if (cur->unresolvedType != NULL && cur->type == 0)
{
FixupTyPars(cur->unresolvedType);
cur->type = PASM->ResolveTypeSpec(cur->unresolvedType);
}
cur = cur->Next();
}
}
/**************************************************************************/
static unsigned corCountArgs(BinStr* args)
{
unsigned __int8* ptr = args->ptr();
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/ilasm/grammar_before.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ static char* newString(_In_ __nullterminated const char* str1);
static void corEmitInt(BinStr* buff, unsigned data);
static void AppendStringWithLength(BinStr* pbs, _In_ __nullterminated char* sz);
static void AppendFieldToCustomBlob(BinStr* pBlob, _In_ BinStr* pField);
static unsigned corCountArgs(BinStr* args);
void yyerror(_In_ __nullterminated const char*);
Instr* SetupInstr(unsigned short);
int yylex();
void ResolveTyParList(TyParList* list);
bool bParsingByteArray = FALSE;
int iOpcodeLen = 0;
int iCallConv = 0;
Expand Down
Loading
Loading