Simplify implicit cast ctors for vector & matrix. #6408
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #6405, and helps with #6358.
This pull request introduces a new builtin type constraint to express "T is implicitly convertible to U", and use this constraint to turn many vector/matrix ctor overloads into a single generic ctor.
Previously, our core module defines:
These overloads results in large core module size, and makes overload resolution slower than it needs to be.
With this cleanup, we are now expressing this with a generic ctor:
The main change here is to implicit the new
T(U) implicit
type constraint (TypeCoercionConstraint
) in a minimal form that is just enough to express the core module functionality.In the future we can expand the language to fully support this new type of constraint for user code. For now the implementation is very limited in that we are cutting a lot of corners by not forming any real witness object to represent how the constraint can be satisfied, and the implementation is not functional for anything but the core module use.
Summary from copilot attached below.
Type Coercion and Conversion Enhancements:
TypeCoercionWitness
class and corresponding methods to handle type coercion witnesses inslang-ast-val.h
andslang-ast-val.cpp
. [1] [2]TypeCoercionConstraintDecl
class inslang-ast-decl.h
to represent type coercion constraints.getTypeCoercionWitness
method inASTBuilder
class to create or retrieve type coercion witnesses inslang-ast-builder.cpp
andslang-ast-builder.h
. [1] [2]getImplicitConversionCostWithKnownArg
and_coerce
methods to handle type coercion constraints inslang-check-conversion.cpp
. [1] [2] [3]visitTypeCoercionConstraintDecl
method toSemanticsDeclHeaderVisitor
for validating type coercion constraints inslang-check-decl.cpp
. [1] [2]IR Instructions and Handling:
BuiltinCast
IR instruction inslang-ir-inst-defs.h
and updatedIRBuilder
to handle it inslang-ir-insts.h
andslang-ir.cpp
. [1] [2] [3]BuiltinCast
inslang-ir-peephole.cpp
.Miscellaneous:
core.meta.slang
. [1] [2]kConversionCost_TypeCoercionConstraint
and related constants inslang-ast-support-types.h
.ImplicitConversionModifier
to set default values for conversion cost and kind inslang-ast-modifier.h
.slang-check-overload.cpp
.slang-check-constraint.cpp
. [1] [2]These changes collectively enhance the type coercion and conversion mechanisms, improve IR handling, and streamline the codebase.