mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-02-21 11:22:42 +00:00
Infer types of module-scope let declarations
This commit is contained in:
parent
d4bedafbda
commit
c1eed779fe
@ -3821,11 +3821,19 @@ impl Parser {
|
||||
lexer.expect(Token::Separator(';'))?;
|
||||
}
|
||||
(Token::Word("let"), _) => {
|
||||
let (name, name_span, explicit_ty, _access) = self.parse_variable_ident_decl(
|
||||
lexer,
|
||||
&mut module.types,
|
||||
&mut module.constants,
|
||||
)?;
|
||||
let (name, name_span) = lexer.next_ident_with_span()?;
|
||||
let given_ty = if lexer.skip(Token::Separator(':')) {
|
||||
let (ty, _access) = self.parse_type_decl(
|
||||
lexer,
|
||||
None,
|
||||
&mut module.types,
|
||||
&mut module.constants,
|
||||
)?;
|
||||
Some(ty)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
lexer.expect(Token::Operation('='))?;
|
||||
let first_token_span = lexer.next();
|
||||
let const_handle = self.parse_const_expression_impl(
|
||||
@ -3835,21 +3843,24 @@ impl Parser {
|
||||
&mut module.types,
|
||||
&mut module.constants,
|
||||
)?;
|
||||
let con = &module.constants[const_handle];
|
||||
let type_match = match con.inner {
|
||||
crate::ConstantInner::Scalar { width, value } => {
|
||||
module.types[explicit_ty].inner
|
||||
== crate::TypeInner::Scalar {
|
||||
kind: value.scalar_kind(),
|
||||
width,
|
||||
}
|
||||
|
||||
if let Some(explicit_ty) = given_ty {
|
||||
let con = &module.constants[const_handle];
|
||||
let type_match = match con.inner {
|
||||
crate::ConstantInner::Scalar { width, value } => {
|
||||
module.types[explicit_ty].inner
|
||||
== crate::TypeInner::Scalar {
|
||||
kind: value.scalar_kind(),
|
||||
width,
|
||||
}
|
||||
}
|
||||
crate::ConstantInner::Composite { ty, components: _ } => ty == explicit_ty,
|
||||
};
|
||||
if !type_match {
|
||||
return Err(Error::InitializationTypeMismatch(name_span, explicit_ty));
|
||||
}
|
||||
crate::ConstantInner::Composite { ty, components: _ } => ty == explicit_ty,
|
||||
};
|
||||
if !type_match {
|
||||
return Err(Error::InitializationTypeMismatch(name_span, explicit_ty));
|
||||
}
|
||||
//TODO: check `ty` against `const_handle`.
|
||||
|
||||
lexer.expect(Token::Separator(';'))?;
|
||||
lookup_global_expression.insert(name, crate::Expression::Constant(const_handle));
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
//TODO: support splatting constructors for globals?
|
||||
let v_f32_one: vec4<f32> = vec4<f32>(1.0, 1.0, 1.0, 1.0);
|
||||
let v_f32_zero: vec4<f32> = vec4<f32>(0.0, 0.0, 0.0, 0.0);
|
||||
let v_f32_half: vec4<f32> = vec4<f32>(0.5, 0.5, 0.5, 0.5);
|
||||
let v_i32_one: vec4<i32> = vec4<i32>(1, 1, 1, 1);
|
||||
let v_f32_one = vec4<f32>(1.0, 1.0, 1.0, 1.0);
|
||||
let v_f32_zero = vec4<f32>(0.0, 0.0, 0.0, 0.0);
|
||||
let v_f32_half = vec4<f32>(0.5, 0.5, 0.5, 0.5);
|
||||
let v_i32_one = vec4<i32>(1, 1, 1, 1);
|
||||
|
||||
fn builtins() -> vec4<f32> {
|
||||
// select()
|
||||
|
Loading…
Reference in New Issue
Block a user