@@ -797,24 +797,9 @@ struct LoweringVisitor
797
797
lowerTypeEx (type->valueType ));
798
798
}
799
799
800
- RefPtr<Type> visitParameterBlockType (ParameterBlockType* type)
801
- {
802
- // TODO: When doing AST-to-AST lowering, we want to lower
803
- // a `ParameterBlock<T>` just like a `ConstantBuffer<T>`.
804
- //
805
- // HACK: for now we will try to simply lower the type
806
- // directly to its stated element type, and see how
807
- // that works.
808
-
809
- return lowerTypeEx (type->getElementType ());
810
- // return getSession()->getConstantBufferType(
811
- // lowerType(type->getElementType());
812
- }
813
-
814
800
RefPtr<Type> transformSyntaxField (Type* type)
815
801
{
816
- // TODO: how to handle this...
817
- return type;
802
+ return lowerAndLegalizeSimpleType (type);
818
803
}
819
804
820
805
RefPtr<Val> visitIRProxyVal (IRProxyVal* val)
@@ -1807,15 +1792,73 @@ struct LoweringVisitor
1807
1792
1808
1793
static LegalExpr maybeReifyTuple (
1809
1794
LegalExpr legalExpr,
1810
- LegalType expectedType )
1795
+ LegalType expectedLegalType )
1811
1796
{
1812
- if (expectedType .flavor != LegalType::Flavor::simple)
1797
+ if (expectedLegalType .flavor != LegalType::Flavor::simple)
1813
1798
return legalExpr;
1814
1799
1800
+ RefPtr<Type> expectedType = expectedLegalType.getSimple ();
1801
+ if (auto errorType = expectedType->As <ErrorType>())
1802
+ {
1803
+ return legalExpr;
1804
+ }
1805
+
1815
1806
if (legalExpr.getFlavor () == LegalExpr::Flavor::simple)
1816
1807
return legalExpr;
1817
1808
1818
- return LegalExpr (reifyTuple (legalExpr, expectedType.getSimple ()));
1809
+ return LegalExpr (reifyTuple (legalExpr, expectedLegalType.getSimple ()));
1810
+ }
1811
+
1812
+ // This function exists to work around cases where `addArgs` gets called
1813
+ // and the structure of the type expected in context (the legalized parameter
1814
+ // type) differs from the structure of the actual argument.
1815
+ //
1816
+ // This function ignores type information and just adds things based on
1817
+ // what is present in the actual expression.
1818
+ void addArgsWorkaround (
1819
+ ExprWithArgsBase* callExpr,
1820
+ LegalExpr argExpr)
1821
+ {
1822
+
1823
+ switch (argExpr.getFlavor ())
1824
+ {
1825
+ case LegalExpr::Flavor::none:
1826
+ break ;
1827
+
1828
+ case LegalExpr::Flavor::simple:
1829
+ addArg (callExpr, argExpr.getSimple ());
1830
+ break ;
1831
+
1832
+ case LegalExpr::Flavor::tuple:
1833
+ {
1834
+ auto aa = argExpr.getTuple ();
1835
+ auto elementCount = aa->elements .Count ();
1836
+ for (UInt ee = 0 ; ee < elementCount; ++ee)
1837
+ {
1838
+ addArgsWorkaround (callExpr, aa->elements [ee].expr );
1839
+ }
1840
+ }
1841
+ break ;
1842
+
1843
+ case LegalExpr::Flavor::pair:
1844
+ {
1845
+ auto aa = argExpr.getPair ();
1846
+ addArgsWorkaround (callExpr, aa->ordinary );
1847
+ addArgsWorkaround (callExpr, aa->special );
1848
+ }
1849
+ break ;
1850
+
1851
+ case LegalExpr::Flavor::implicitDeref:
1852
+ {
1853
+ auto aa = argExpr.getImplicitDeref ();
1854
+ addArgsWorkaround (callExpr, aa->valueExpr );
1855
+ }
1856
+ break ;
1857
+
1858
+ default :
1859
+ SLANG_UNEXPECTED (" unhandled case" );
1860
+ break ;
1861
+ }
1819
1862
}
1820
1863
1821
1864
void addArgs (
@@ -1827,7 +1870,10 @@ struct LoweringVisitor
1827
1870
1828
1871
if (argExpr.getFlavor () != argType.flavor )
1829
1872
{
1830
- SLANG_UNEXPECTED (" expression and type do not match" );
1873
+ // A mismatch may also arise if we are in the `-no-checking` mode,
1874
+ // so that we are making a call that didn't type-check.
1875
+ addArgsWorkaround (callExpr, argExpr);
1876
+ return ;
1831
1877
}
1832
1878
1833
1879
switch (argExpr.getFlavor ())
@@ -1900,6 +1946,29 @@ struct LoweringVisitor
1900
1946
return LegalExpr (lowerCallExpr (loweredExpr, expr));
1901
1947
}
1902
1948
1949
+ LegalExpr visitHiddenImplicitCastExpr (
1950
+ HiddenImplicitCastExpr* expr)
1951
+ {
1952
+ LegalExpr legalArg = legalizeExpr (expr->Arguments [0 ]);
1953
+ if (legalArg.getFlavor () == LegalExpr::Flavor::simple)
1954
+ {
1955
+ InvokeExpr* loweredExpr = (InvokeExpr*) expr->getClass ().createInstance ();
1956
+ lowerExprCommon (loweredExpr, expr);
1957
+ loweredExpr->FunctionExpr = legalizeSimpleExpr (expr->FunctionExpr );
1958
+ addArg (loweredExpr, legalArg.getSimple ());
1959
+ return LegalExpr (loweredExpr);
1960
+ }
1961
+ else
1962
+ {
1963
+ // If we hit this case, then there seems to have been a type-checking
1964
+ // error around a type that needed to be desugared. We want to use
1965
+ // the original expression rather than hide it behind a cast, because
1966
+ // it might need to be unpacked into multiple arguments for a call, etc.
1967
+ //
1968
+ return legalArg;
1969
+ }
1970
+ }
1971
+
1903
1972
LegalExpr visitSelectExpr (
1904
1973
SelectExpr* expr)
1905
1974
{
@@ -2476,6 +2545,7 @@ struct LoweringVisitor
2476
2545
RefPtr<Type> type)
2477
2546
{
2478
2547
auto typeType = new TypeType ();
2548
+ typeType->setSession (getSession ());
2479
2549
typeType->type = type;
2480
2550
2481
2551
auto result = new SharedTypeExpr ();
@@ -3320,7 +3390,6 @@ struct LoweringVisitor
3320
3390
typeLayout,
3321
3391
legalInit,
3322
3392
legalTypeExpr);
3323
-
3324
3393
}
3325
3394
break ;
3326
3395
@@ -3329,8 +3398,17 @@ struct LoweringVisitor
3329
3398
auto implicitDerefType = legalType.getImplicitDeref ();
3330
3399
3331
3400
auto valueType = implicitDerefType->valueType ;
3332
- auto valueTypeLayout = getDerefTypeLayout (typeLayout);
3333
- SLANG_ASSERT (valueTypeLayout || !typeLayout);
3401
+
3402
+ // Don't apply dereferencing to the type layout, because
3403
+ // other steps will also implicitly remove wrappers (like
3404
+ // parameter groups) and this could mess up the final
3405
+ // type layout for a variable.
3406
+ //
3407
+ // Instead, any other "unwrapping" that needs to occur
3408
+ // when declaring variables should be handled in the
3409
+ // case for the specific type (e.g., when extracting
3410
+ // fields for a tuple, we should auto-dereference).
3411
+ auto valueTypeLayout = typeLayout;
3334
3412
auto valueInit = deref (legalInit);
3335
3413
3336
3414
LegalExpr valueExpr = declareVars (
0 commit comments