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

Don't treat pointers as data. #911

Merged
merged 1 commit into from
Jun 1, 2022
Merged

Conversation

jimblandy
Copy link
Member

@jimblandy jimblandy commented May 27, 2021

All commits should be CI-clean.

  • Don't allow pointers in return values.

  • [wgsl-in]: Use a matches! expression for brevity.

  • Don't permit Expression::Select to operate on pointers. At the moment, Naga
    doesn't support anything like SPIR-V's 'variable pointers'.

  • Naga TypeInner::Pointer types are not TypeFlags::DATA.

    Change Validator::validate_type not to mark pointers with the
    TypeFlags::Data flag. The TypeFlags::DATA flag is supposed to correspond to
    WGSL's concept of a 'plain type': a scalar, atomic, or composite type, excluding
    textures, samplers, and pointers.

    With this change, there is no type where TypeFlags::DATA and
    TypeFlags::INTERFACE differ, but I'm not removing anything in this PR, because
    I think we'll want to re-introduce a different distinction between them soon.

@jimblandy jimblandy requested a review from kvark May 27, 2021 02:47
}
_ => false,
};
let mut needs_deref = allow_deref
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really better than the old code?
I think we should only use macros where their benefit outweight the cost of having an extra layer of indirection. Macros slow down compilation, confuse IDEs, and generally shouldn't be used so sparingly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, this is the case where I think matches! actually works. Putting allow_deref in the first arm of the match is a really obscure way of saying &&. And if you do use &&, then the match just has arms with => true and => false, which is classic matches!. Since this is a std macro, I think IDEs are going to pick up on it pretty quickly; rust-analyzer, at least, hasn't been having any problems with it.

But if you don't find that persuasive, it's not something I feel strongly about.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I agree. It's not striking me as a case that would need to be an exception though if we try to avoid matches in general (I checked briefly and didn't find a clippy for this).

@@ -755,6 +755,9 @@ impl super::Validator {
if !condition_good || accept_inner != reject_inner {
return Err(ExpressionError::InvalidSelectTypes);
}
if let Ti::Pointer { .. } = *accept_inner {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a wrong level to check this. We are checking for pointers, but what if it's a texture, for example?
Instead, we need to check the derived type flags on this and ensure this is DATA | SIZED

@teoxoy
Copy link
Member

teoxoy commented Apr 28, 2022

@jimblandy what is the status of this PR?

@jimblandy
Copy link
Member Author

Probably stale. It needs to be reevaluated in light of the current state of the language spec and the code, which has evolved.

@jimblandy
Copy link
Member Author

The easiest thing to do would be to demote it (re-file it) as an issue instead of a PR.

@jimblandy jimblandy marked this pull request as draft May 1, 2022 05:32
@jimblandy
Copy link
Member Author

Converted to draft - just realized there were other commits on the branch I hadn't noticed, and whose changes need to be incorporated.

Introduce a new `TypeFlags::CONSTRUCTIBLE` flag, corresponding to
WGSL's "constructible types". Set this on the appropriate types.
Check for this flag on function return types.
@jimblandy jimblandy marked this pull request as ready for review May 26, 2022 00:24
@jimblandy jimblandy requested a review from kvark May 26, 2022 00:25
Copy link
Member

@teoxoy teoxoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description is a bit outdated but the changes look good

@jimblandy jimblandy merged commit 89bed99 into gfx-rs:master Jun 1, 2022
@jimblandy jimblandy deleted the pointer-not-data branch June 1, 2022 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants