Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output an accurate error message when unimplemented math functions are called (globally) #1501

Merged
merged 1 commit into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/front/glsl/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub enum ConstantSolvingError {
SplatScalarOnly,
#[error("Can only swizzle vector constants")]
SwizzleVectorOnly,
#[error("Not implemented: {0}")]
#[error("Not implemented as constant expression: {0}")]
NotImplemented(String),
}

Expand Down
1 change: 1 addition & 0 deletions src/front/glsl/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ impl Parser {

pub struct DeclarationContext<'ctx, 'qualifiers> {
qualifiers: TypeQualifiers<'qualifiers>,
/// Indicates a global declaration
external: bool,

ctx: &'ctx mut Context,
Expand Down
22 changes: 17 additions & 5 deletions src/front/glsl/parser/declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,23 @@ impl<'source> ParsingContext<'source> {
})
.transpose()?;

// TODO: Should we try to make constants here?
// This is mostly a hack because we don't yet support adding
// bodies to entry points for variable initialization
let maybe_constant =
init.and_then(|(root, meta)| parser.solve_constant(ctx.ctx, root, meta).ok());
// If the declaration has an initializer try to make a constant out of it,
// this is only strictly needed for global constant declarations (and if the
// initializer can't be made a constant it should throw an error) but we also
// try to do it for all other types of declarations.
let maybe_constant = if let Some((root, meta)) = init {
let is_const = ctx.qualifiers.storage.0 == StorageQualifier::Const;

match parser.solve_constant(ctx.ctx, root, meta) {
Ok(res) => Some(res),
// If the declaration is external (global scope) and is constant qualified
// then the initializer must be a constant expression
Err(err) if ctx.external && is_const => return Err(err),
_ => None,
}
} else {
None
};

let pointer = ctx.add_var(parser, ty, name, maybe_constant, meta)?;

Expand Down