Skip to content

Commit ce87911

Browse files
committed
Improvements and bug fixes for global type parameters
1. allow spReflection_FindTypeByName to accept arbitrary type expression string 2. allow const int generic value to be used as expression value, and as array size 3. various bug fixes in witness table specialization / function cloning during specializeIRForEntryPoint to avoid creating duplicate global values, not copying the right definition of a function from the other module, not cloning witness tables that are required by specializeGenerics etc.
1 parent 913f4d0 commit ce87911

16 files changed

+282
-116
lines changed

source/slang/check.cpp

+20-9
Original file line numberDiff line numberDiff line change
@@ -6849,6 +6849,23 @@ namespace Slang
68496849
return (!decl->primaryDecl) || (decl == decl->primaryDecl);
68506850
}
68516851

6852+
RefPtr<Type> checkProperType(TranslationUnitRequest * tu, TypeExp typeExp)
6853+
{
6854+
RefPtr<Type> type;
6855+
DiagnosticSink nSink;
6856+
nSink.sourceManager = tu->compileRequest->sourceManager;
6857+
SemanticsVisitor visitor(
6858+
&nSink,
6859+
tu->compileRequest,
6860+
tu);
6861+
auto typeOut = visitor.CheckProperType(typeExp);
6862+
if (!nSink.errorCount)
6863+
{
6864+
type = typeOut.type;
6865+
}
6866+
return type;
6867+
}
6868+
68526869
void validateEntryPoint(
68536870
EntryPointRequest* entryPoint)
68546871
{
@@ -6956,15 +6973,9 @@ namespace Slang
69566973
{
69576974
RefPtr<Expr> typeExpr = entryPoint->compileRequest->parseTypeString(entryPoint->getTranslationUnit(),
69586975
name, s);
6959-
DiagnosticSink nSink;
6960-
SemanticsVisitor visitor(
6961-
&nSink,
6962-
translationUnit->compileRequest,
6963-
translationUnit);
6964-
auto typeOut = visitor.CheckProperType(TypeExp(typeExpr));
6965-
if (!nSink.errorCount)
6966-
{
6967-
type = typeOut.type;
6976+
type = checkProperType(translationUnit, TypeExp(typeExpr));
6977+
if (type)
6978+
{
69686979
break;
69696980
}
69706981
}

source/slang/compiler.h

+2
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ namespace Slang
319319
~CompileRequest();
320320

321321
RefPtr<Expr> parseTypeString(TranslationUnitRequest * translationUnit, String typeStr, RefPtr<Scope> scope);
322+
323+
Type* getTypeFromString(String typeStr);
322324

323325
void parseTranslationUnit(
324326
TranslationUnitRequest* translationUnit);

source/slang/emit.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7500,7 +7500,7 @@ String emitEntryPoint(
75007500
// none of our target supports generics, or interfaces,
75017501
// so we need to specialize those away.
75027502
//
7503-
specializeGenerics(irModule);
7503+
specializeGenerics(irModule, sharedContext.target);
75047504

75057505
// Debugging code for IR transformations...
75067506
#if 0

source/slang/ir-insts.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,8 @@ void specializeIRForEntryPoint(
641641
// Find suitable uses of the `specialize` instruction that
642642
// can be replaced with references to specialized functions.
643643
void specializeGenerics(
644-
IRModule* module);
644+
IRModule* module,
645+
CodeGenTarget target);
645646

646647
//
647648

0 commit comments

Comments
 (0)