intrinsic_table.def: Support [[deprecated]] on fn

And produce a warning if these are used. Hard to test, as we don't want to introduce fake functions in our definition file.

Also add missing cast in EnumMatcher.

Bug: tint:806
Change-Id: I21f189e4befe419f6d5544acfc52387d9a5da782
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/54001
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
Ben Clayton 2021-06-10 17:31:54 +00:00 committed by Tint LUCI CQ
parent 06e2e5c2f7
commit 3e59eb0e5c
9 changed files with 289 additions and 9 deletions

View File

@ -663,10 +663,12 @@ struct OverloadInfo {
ParameterInfo const* const parameters; ParameterInfo const* const parameters;
/// Pointer to a list of matcher indices that index on Matchers::type and /// Pointer to a list of matcher indices that index on Matchers::type and
/// Matchers::number, used to build the return type. If the function has no /// Matchers::number, used to build the return type. If the function has no
/// return type then this is null. /// return type then this is null
MatcherIndex const* const return_matcher_indices; MatcherIndex const* const return_matcher_indices;
/// The pipeline stages that this overload can be used in. /// The pipeline stages that this overload can be used in
PipelineStageSet supported_stages; PipelineStageSet supported_stages;
/// True if the overload is marked as deprecated
bool is_deprecated;
}; };
/// IntrinsicInfo describes an intrinsic function /// IntrinsicInfo describes an intrinsic function
@ -878,7 +880,7 @@ const sem::Intrinsic* Impl::Match(sem::IntrinsicType intrinsic_type,
return builder.create<sem::Intrinsic>( return builder.create<sem::Intrinsic>(
intrinsic_type, const_cast<sem::Type*>(return_type), intrinsic_type, const_cast<sem::Type*>(return_type),
std::move(parameters), overload.supported_stages); std::move(parameters), overload.supported_stages, overload.is_deprecated);
} }
MatchState Impl::Match(ClosedState& closed, MatchState Impl::Match(ClosedState& closed,

File diff suppressed because it is too large Load Diff

View File

@ -101,6 +101,7 @@ constexpr OverloadInfo kOverloads[] = {
{{- range $i, $u := $o.CanBeUsedInStage.List -}} {{- range $i, $u := $o.CanBeUsedInStage.List -}}
{{- if $i -}}, {{end}}PipelineStage::k{{Title $u}} {{- if $i -}}, {{end}}PipelineStage::k{{Title $u}}
{{- end }}), {{- end }}),
/* is_deprecated */ {{$o.IsDeprecated}},
}, },
{{- end }} {{- end }}
}; };
@ -247,7 +248,7 @@ class {{$class}} : public NumberMatcher {
{{- $entry := printf "k%v" (PascalCase $option.Name) -}} {{- $entry := printf "k%v" (PascalCase $option.Name) -}}
Number {{$class}}::Match(MatchState&, Number number) const { Number {{$class}}::Match(MatchState&, Number number) const {
if (number.IsAny() || number.Value() == static_cast<uint32_t>({{$enum}}::{{$entry}})) { if (number.IsAny() || number.Value() == static_cast<uint32_t>({{$enum}}::{{$entry}})) {
return Number({{$enum}}::{{$entry}}); return Number(static_cast<uint32_t>({{$enum}}::{{$entry}}));
} }
return Number::invalid; return Number::invalid;
} }

View File

@ -1723,6 +1723,10 @@ bool Resolver::IntrinsicCall(ast::CallExpression* call,
return false; return false;
} }
if (result->IsDeprecated()) {
diagnostics_.add_warning("use of deprecated intrinsic", call->source());
}
builder_->Sem().Add( builder_->Sem().Add(
call, builder_->create<sem::Call>(call, result, current_statement_)); call, builder_->create<sem::Call>(call, result, current_statement_));
SetType(call, result->ReturnType()); SetType(call, result->ReturnType());

View File

@ -90,10 +90,12 @@ bool IsBarrierIntrinsic(IntrinsicType i) {
Intrinsic::Intrinsic(IntrinsicType type, Intrinsic::Intrinsic(IntrinsicType type,
sem::Type* return_type, sem::Type* return_type,
const ParameterList& parameters, const ParameterList& parameters,
PipelineStageSet supported_stages) PipelineStageSet supported_stages,
bool is_deprecated)
: Base(return_type, parameters), : Base(return_type, parameters),
type_(type), type_(type),
supported_stages_(supported_stages) {} supported_stages_(supported_stages),
is_deprecated_(is_deprecated) {}
Intrinsic::~Intrinsic() = default; Intrinsic::~Intrinsic() = default;

View File

@ -78,10 +78,13 @@ class Intrinsic : public Castable<Intrinsic, CallTarget> {
/// @param parameters the parameters for the intrinsic overload /// @param parameters the parameters for the intrinsic overload
/// @param supported_stages the pipeline stages that this intrinsic can be /// @param supported_stages the pipeline stages that this intrinsic can be
/// used in /// used in
/// @param is_deprecated true if the particular overload is considered
/// deprecated
Intrinsic(IntrinsicType type, Intrinsic(IntrinsicType type,
sem::Type* return_type, sem::Type* return_type,
const ParameterList& parameters, const ParameterList& parameters,
PipelineStageSet supported_stages); PipelineStageSet supported_stages,
bool is_deprecated);
/// Destructor /// Destructor
~Intrinsic() override; ~Intrinsic() override;
@ -92,6 +95,9 @@ class Intrinsic : public Castable<Intrinsic, CallTarget> {
/// @return the pipeline stages that this intrinsic can be used in /// @return the pipeline stages that this intrinsic can be used in
PipelineStageSet SupportedStages() const { return supported_stages_; } PipelineStageSet SupportedStages() const { return supported_stages_; }
/// @return true if the intrinsic overload is considered deprecated
bool IsDeprecated() const { return is_deprecated_; }
/// @returns the name of the intrinsic function type. The spelling, including /// @returns the name of the intrinsic function type. The spelling, including
/// case, matches the name in the WGSL spec. /// case, matches the name in the WGSL spec.
const char* str() const; const char* str() const;
@ -126,6 +132,7 @@ class Intrinsic : public Castable<Intrinsic, CallTarget> {
private: private:
IntrinsicType const type_; IntrinsicType const type_;
PipelineStageSet const supported_stages_; PipelineStageSet const supported_stages_;
bool const is_deprecated_;
}; };
/// Emits the name of the intrinsic function type. The spelling, including case, /// Emits the name of the intrinsic function type. The spelling, including case,

View File

@ -98,6 +98,8 @@ type Overload struct {
ReturnMatcherIndicesOffset *int ReturnMatcherIndicesOffset *int
// StageUses describes the stages an overload can be used in // StageUses describes the stages an overload can be used in
CanBeUsedInStage sem.StageUses CanBeUsedInStage sem.StageUses
// True if the overload is marked as deprecated
IsDeprecated bool
} }
// Function is used to create the C++ IntrinsicInfo structure // Function is used to create the C++ IntrinsicInfo structure
@ -196,6 +198,7 @@ func (b *intrinsicTableBuilder) buildOverload(o *sem.Overload) (Overload, error)
ParametersOffset: b.lut.parameters.Add(ob.parameters), ParametersOffset: b.lut.parameters.Add(ob.parameters),
ReturnMatcherIndicesOffset: ob.returnTypeMatcherIndicesOffset, ReturnMatcherIndicesOffset: ob.returnTypeMatcherIndicesOffset,
CanBeUsedInStage: o.CanBeUsedInStage, CanBeUsedInStage: o.CanBeUsedInStage,
IsDeprecated: o.IsDeprecated,
}, nil }, nil
} }

View File

@ -275,6 +275,12 @@ func (r *resolver) function(a ast.FunctionDecl) error {
Compute: true, Compute: true,
} }
} }
if deprecated := a.Decorations.Take("deprecated"); deprecated != nil {
overload.IsDeprecated = true
if len(deprecated.Values) != 0 {
return fmt.Errorf("%v unexpected value for deprecated decoration", deprecated.Source)
}
}
if len(a.Decorations) != 0 { if len(a.Decorations) != 0 {
return fmt.Errorf("%v unknown decoration", a.Decorations[0].Source) return fmt.Errorf("%v unknown decoration", a.Decorations[0].Source)
} }

View File

@ -137,6 +137,7 @@ type Overload struct {
ReturnType *FullyQualifiedName ReturnType *FullyQualifiedName
Parameters []Parameter Parameters []Parameter
CanBeUsedInStage StageUses CanBeUsedInStage StageUses
IsDeprecated bool // True if this overload is deprecated
} }
// StageUses describes the stages an overload can be used in // StageUses describes the stages an overload can be used in