Skip to content

Commit 4044a1d

Browse files
authored
Merge pull request shader-slang#372 from csyonghe/master
Allow type expression as type argument, fix global param enum order
2 parents 2079b94 + f681a15 commit 4044a1d

23 files changed

+376
-126
lines changed

source/slang/check.cpp

+32-16
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
{
@@ -6944,26 +6961,25 @@ namespace Slang
69446961
entryPoint->decl = entryPointFuncDecl;
69456962

69466963
// Lookup generic parameter types in global scope
6964+
List<RefPtr<Scope>> scopesToTry;
6965+
scopesToTry.Add(entryPoint->getTranslationUnit()->SyntaxNode->scope);
6966+
for (auto & module : entryPoint->compileRequest->loadedModulesList)
6967+
scopesToTry.Add(module->moduleDecl->scope);
69476968
for (auto name : entryPoint->genericParameterTypeNames)
6948-
{
6949-
firstDeclWithName = entryPoint->compileRequest->lookupGlobalDecl(name);
6950-
if (!firstDeclWithName)
6951-
{
6952-
// If there doesn't appear to be any such declaration, then
6953-
// we need to diagnose it as an error, and then bail out.
6954-
sink->diagnose(translationUnitSyntax, Diagnostics::entryPointTypeParameterNotFound, name);
6955-
return;
6956-
}
6969+
{
6970+
// parse type name
69576971
RefPtr<Type> type;
6958-
if (auto aggType = firstDeclWithName->As<AggTypeDecl>())
6959-
{
6960-
type = DeclRefType::Create(entryPoint->compileRequest->mSession, DeclRef<Decl>(aggType, nullptr));
6961-
}
6962-
else if (auto typeDefDecl = firstDeclWithName->As<TypeDefDecl>())
6972+
for (auto & s : scopesToTry)
69636973
{
6964-
type = GetType(DeclRef<TypeDefDecl>(typeDefDecl, nullptr));
6974+
RefPtr<Expr> typeExpr = entryPoint->compileRequest->parseTypeString(entryPoint->getTranslationUnit(),
6975+
name, s);
6976+
type = checkProperType(translationUnit, TypeExp(typeExpr));
6977+
if (type)
6978+
{
6979+
break;
6980+
}
69656981
}
6966-
else
6982+
if (!type)
69676983
{
69686984
sink->diagnose(firstDeclWithName, Diagnostics::entryPointTypeSymbolNotAType, name);
69696985
return;

source/slang/compiler.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ namespace Slang
104104

105105
// The type names we want to substitute into the
106106
// global generic type parameters
107-
List<Name*> genericParameterTypeNames;
107+
List<String> genericParameterTypeNames;
108108

109109
// The profile that the entry point will be compiled for
110110
// (this is a combination of the target state, and also
@@ -318,6 +318,10 @@ namespace Slang
318318

319319
~CompileRequest();
320320

321+
RefPtr<Expr> parseTypeString(TranslationUnitRequest * translationUnit, String typeStr, RefPtr<Scope> scope);
322+
323+
Type* getTypeFromString(String typeStr);
324+
321325
void parseTranslationUnit(
322326
TranslationUnitRequest* translationUnit);
323327

source/slang/decl-defs.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ SIMPLE_SYNTAX_CLASS(Variable, VarDeclBase);
196196

197197
// A "module" of code (essentiately, a single translation unit)
198198
// that provides a scope for some number of declarations.
199-
SIMPLE_SYNTAX_CLASS(ModuleDecl, ContainerDecl)
199+
SYNTAX_CLASS(ModuleDecl, ContainerDecl)
200+
FIELD(RefPtr<Scope>, scope)
201+
END_SYNTAX_CLASS()
200202

201203
SYNTAX_CLASS(ImportDecl, Decl)
202204
// The name of the module we are trying to import

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)