[msl-out] Write 'using metal::uint' at the top, to work around bug. (#1740)

This lets us remove some special cases where `uint` must be fully
qualified, even though other similar types are not.
This commit is contained in:
Jim Blandy
2022-02-21 13:22:54 -08:00
committed by GitHub
parent 1ccfc8991e
commit 688ad474f7
27 changed files with 145 additions and 95 deletions

View File

@@ -18,6 +18,7 @@ pub const RESERVED: &[&str] = &[
"bool",
"char",
"int",
"uint",
"long",
"float",
"double",

View File

@@ -39,10 +39,6 @@ fn put_numeric_type(
sizes: &[crate::VectorSize],
) -> Result<(), FmtError> {
match (kind, sizes) {
(crate::ScalarKind::Uint, &[]) => {
// Work around Metal compiler bug: scalar `uint` requires namespace.
write!(out, "{}::uint", NAMESPACE)
}
(kind, &[]) => {
write!(out, "{}", kind.to_msl_name())
}
@@ -1434,7 +1430,7 @@ impl<W: Write> Writer<W> {
/// The text written is of the form:
///
/// ```ignore
/// {level}{prefix}metal::uint(i) < 4 && metal::uint(j) < 10
/// {level}{prefix}uint(i) < 4 && uint(j) < 10
/// ```
///
/// where `{level}` and `{prefix}` are the arguments to this function. For [`Store`]
@@ -1494,7 +1490,7 @@ impl<W: Write> Writer<W> {
// Check that the index falls within bounds. Do this with a single
// comparison, by casting the index to `uint` first, so that negative
// indices become large positive values.
write!(self.out, "{}::uint(", NAMESPACE)?;
write!(self.out, "uint(")?;
self.put_index(index, context, true)?;
self.out.write_str(") < ")?;
match length {
@@ -2351,6 +2347,9 @@ impl<W: Write> Writer<W> {
writeln!(self.out, "#include <metal_stdlib>")?;
writeln!(self.out, "#include <simd/simd.h>")?;
writeln!(self.out)?;
// Work around Metal bug where `uint` is not available by default
writeln!(self.out, "using {}::uint;", NAMESPACE)?;
writeln!(self.out)?;
if options
.bounds_check_policies
@@ -2372,7 +2371,7 @@ impl<W: Write> Writer<W> {
writeln!(self.out, "struct _mslBufferSizes {{")?;
for idx in indices {
writeln!(self.out, "{}{}::uint size{};", back::INDENT, NAMESPACE, idx)?;
writeln!(self.out, "{}uint size{};", back::INDENT, idx)?;
}
writeln!(self.out, "}};")?;