summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-ir-specialize.cpp7
-rw-r--r--source/slang/slang-ir.cpp29
-rw-r--r--source/slang/slang-lower-to-ir.cpp6
-rw-r--r--source/slang/slang.cpp1
4 files changed, 31 insertions, 12 deletions
diff --git a/source/slang/slang-ir-specialize.cpp b/source/slang/slang-ir-specialize.cpp
index d4f236138..cf475f1ff 100644
--- a/source/slang/slang-ir-specialize.cpp
+++ b/source/slang/slang-ir-specialize.cpp
@@ -267,6 +267,13 @@ struct SpecializationContext
IRGeneric* g = generic;
for(;;)
{
+ // We can't specialize a generic if it is marked as
+ // being imported from an external module (in which
+ // case its definition is not available to us).
+ //
+ if(!isDefinition(g))
+ return false;
+
// Given the generic `g`, we will find the value
// it appears to return in its body.
//
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp
index 45cbd65ff..9a44787ff 100644
--- a/source/slang/slang-ir.cpp
+++ b/source/slang/slang-ir.cpp
@@ -5068,6 +5068,13 @@ namespace Slang
// the value they return.
for(;;)
{
+ // An instruciton marked `[import(...)]` cannot
+ // be a definition, since it is claiming that
+ // the actual body comes from another module.
+ //
+ if(val->findDecoration<IRImportDecoration>())
+ return false;
+
auto genericInst = as<IRGeneric>(val);
if(!genericInst)
break;
@@ -5079,13 +5086,12 @@ namespace Slang
val = returnVal;
}
- // TODO: the logic here should probably
- // be that anything with an `IRImportDecoration`
- // is considered to be a declaration rather than definition.
-
+ // Some cases of instructions have structural
+ // rules about when they are considered to have
+ // a definition (e.g., a function must have a body).
+ //
switch (val->op)
{
- case kIROp_WitnessTable:
case kIROp_Func:
case kIROp_Generic:
return val->getFirstChild() != nullptr;
@@ -5093,14 +5099,15 @@ namespace Slang
case kIROp_GlobalConstant:
return cast<IRGlobalConstant>(val)->getValue() != nullptr;
- case kIROp_StructType:
- case kIROp_GlobalVar:
- case kIROp_GlobalParam:
- return true;
-
default:
- return false;
+ break;
}
+
+ // In all other cases, if we have an instruciton
+ // that has *not* been marked for import, then
+ // we consider it to be a definition.
+
+ return true;
}
void markConstExpr(
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp
index 009e776bb..aaa9d1a4c 100644
--- a/source/slang/slang-lower-to-ir.cpp
+++ b/source/slang/slang-lower-to-ir.cpp
@@ -6711,13 +6711,17 @@ static void ensureAllDeclsRec(
// Aggregate types are the main case where we can emit an outer declaration
// and not the stuff nested inside of it.
//
- if(auto containerDecl = as<AggTypeDecl>(decl))
+ if(auto containerDecl = as<AggTypeDeclBase>(decl))
{
for (auto memberDecl : containerDecl->Members)
{
ensureAllDeclsRec(context, memberDecl);
}
}
+ else if (auto genericDecl = as<GenericDecl>(decl))
+ {
+ ensureAllDeclsRec(context, genericDecl->inner);
+ }
}
IRModule* generateIRForTranslationUnit(
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index aefe70a4a..1f8f79af2 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -1544,6 +1544,7 @@ RefPtr<Module> Linkage::loadModule(
RefPtr<TranslationUnitRequest> translationUnit = new TranslationUnitRequest(frontEndReq);
translationUnit->compileRequest = frontEndReq;
translationUnit->moduleName = name;
+ translationUnit->sourceLanguage = SourceLanguage::Slang;
auto module = translationUnit->getModule();