Commit Graph

16 Commits

Author SHA1 Message Date
Ben Clayton 5b36d2c612 Remove all unnecessary includes
All includes from .cc to .h are preserved, even when transitively included.

It's clear that there are far too many includes in header files, and we should be more aggressive with forward declarations. tint:532 will continue to track this work.

There are, however, plenty of includes that have accumulated over time which are no longer required directly or transitively, so this change starts with a clean slate of *required* includes.

Bug: tint:532
Change-Id: Ie1718dad565f8309fa180ef91bcf3920e76dba18
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44042
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-03-09 11:11:17 +00:00
Ben Clayton ce9229cd2e Program: Fix move of diagnostics.
Add test.

Change-Id: Ide47df8b3a946818ed9a8ffd62411284f568609b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42262
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2021-02-24 13:51:13 +00:00
Ben Clayton 527a0bbf25 Have Program::IsValid() return false unless built
An unbuilt program doesn't have an ast::Module, so Program::AST() will just explode.

* Have a Program default to false for IsValid()
* Initialize the ast_ field to nullptr. This was previously floating.
* Return from CommonFuzzer::Run() earlier if the InputFormat is not recognised.

Fixed: chromium:1180130
Fixed: chromium:1180157
Change-Id: I9b67daa10746f386f44919a7b9ac5c171092d6e5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42028
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: David Neto <dneto@google.com>
2021-02-19 19:04:18 +00:00
Ben Clayton 37571bc32d ProgramBuilder: Swap parameter order for Var and Const
Move the storage parameter after type.
Const() has no use for storage classes, so this parameter will be removed in the next change.
This reordering keeps Var() and Const() parameter types identical for the first two non-optional fields

Change-Id: I66669d19fa2175c4f10f615941e69efcab4c23e1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41540
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-16 23:57:01 +00:00
James Price 3eaa450984 [ast] Add ast::Module::AddFunction()
Remove the non-const ast::Module::Functions() getter.

Change-Id: I365eece04837ee6bd51147d226c73e04ce5d9bd4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41300
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: James Price <jrprice@google.com>
2021-02-09 21:26:21 +00:00
Ben Clayton 401b96b9bb Simplify usage of the TypeDeterminer in tests
Make private all TypeDeterminer::DetermineXXX() methods, forcing all tests to use the root-level TypeDeterminer::Determine() method.
Remove TypeDeterminer::RegisterVariableForTesting().

The main use for calling the TypeDeterminer::DetermineXXX() methods was to perform type determination on a partial AST.
This was messy and often resulting in multiple calls into TypeDeterminer. Most tests already perform a full TypeDeterminer::Determine() call when the program is built, so many of these were redundant.
The exposure of these internal methods for testing also makes refactoring the TypeDeterminer extremely difficult.

Add a number of ProgramBuilder helper methods for attaching the partial AST in these tests to the root of the AST, greatly simplifying the use of the TypeDeterminer:
* ProgramBuilder::Global() and ProgramBuilder::GlobalConst() are helpers that register the variable returned by ProgramBuilder::Var() and ProgramBuilder::Const(), respectively.
* ProgramBuilder::WrapInFunction() is a variadic function that accepts variables, expressions and statements, attaching these to the root of the AST via a dummy function.

Most test classes now no longer use their own TypeDeterminer, and instead properly depend on the automatic type determination performed at Program build time.

Bug: tint:390
Change-Id: Ie901890420c5de170cdf2a7aaef9b96fc3bebd60
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40062
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-02-03 17:19:59 +00:00
Ben Clayton 90da745fbd Program: Fix IsValid() state on TypeDeterminer error
The error was added to diagnostics_, and then this list was replaced with diagnostics from the builder.
This resulted in the error silently being dropped.

Change-Id: Ifdda99bfb1582fa5d0fa691f7d39cfe3f17e60e5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39901
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-02 15:06:05 +00:00
Ben Clayton 42d1e097e6 Have ProgramBuilder::Func() register the function
With the ast::Module::Functions().

Also remove pointless calls to td.Determine() that will automatically be
done when the program is built.

Change-Id: Ia7506e430b04d91d4f6b02fb6b678d0ea9912bcd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39900
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-02 14:29:15 +00:00
Ben Clayton 844217fa34 Add Diagnostics to Program, reader::[wgsl,spirv]::Parse()
By putting diagnostics into the program, we can hold all the diagnostic messages for parsing and type determination in one place.
This also means that we can simplify the public WGSL and SPIR-V Parser interfaces to a single function.

Change-Id: Ib6ab5fa180addd45c4aaf0c6b192d47182ffb50a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38920
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-01-27 18:49:05 +00:00
Ben Clayton a6b9a8eb2f Split Program into Program and ProgramBuilder
Program is now immutable*, and remains part of the public Tint
interface.

ProgramBuilder is the mutable builder for Programs, and is not part of
the public Tint interface. ast::Builder has been folded into
ProgramBuilder.

Immutable Programs can be cloned into a mutable ProgramBuilder with
Program::CloneAsBuilder().

Mutable ProgramBuilders can be moved into immutable Programs.

* - mostly immutable. It still has a move constructor and move
  assignment operator - required for practical usage - and the
  semantic information on AST nodes is still mutable.

Bug: tint:390
Change-Id: Ia856c50b1880c2f95c91467a9eef5024cbc380c6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38240
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00
Ben Clayton 1f7e18bbc0 ast::Builder: Add shortcuts to the Program methods
This builder will be merged into ProgramBuilder, where these will become methods.
To breakup this change, perform the refactoring as a separate change.

Bug: tint:390
Change-Id: I2c9151cd9f198e99d88eaf296dd994293df6c425
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38720
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00
Ben Clayton 8d391f7a10 ast::TypesBuilder: Change const fields to getters
This is required in order to support move operators for TypesBuilder.

Bug: tint:390
Change-Id: I9667bda5f5be267df092f5cd94dc40db053ae6e2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38555
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00
Ben Clayton 83158f214f Program: Remove deprecated function methods
Fixup all usages

Bug: tint:390
Change-Id: I949235908e50702d6c8b2e7e2299594879653e01
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38547
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00
Ben Clayton 1b3d6e460c Program: Remove deprecated constructed-type methods
Fixup all usages

Bug: tint:390
Change-Id: I739a7625cd385cb889369ab7c766462fbcd7cf12
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38546
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00
Ben Clayton a86f4effe4 Program: Remove deprecated global variable methods
Fixup all usages

Bug: tint:390
Change-Id: I2e239dfc77872acb9f0b2ee5494350605dd780a1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38545
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00
Ben Clayton c40f627bea Migrate from using ast::Module to Program
Enforce all places where Dawn passes in or returns a ast::Module, now takes a `const Program* ` or returns a `Program`.

As the end goal of all this is to have immutable Programs, all Program inputs take a pointer instead of moving the actual object.

As consumers of a Program are now all const, we have to const_cast to work around all the places we've been incorrectly mutating a ast::Module.
These const_casts are temporary, and will be fixed in the next set of changes.

Depends on https://dawn-review.googlesource.com/c/dawn/+/38522

Bug: tint:390
Change-Id: Ie05b112b16134937d1b601e9b713ea4ec4e1c677
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38541
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00