Standardize the use of UNREACHABLE in switches.

A lot of our switches over enum values use the following pattern:

    default:
        UNREACHABLE();
        return foo;

This is problematic because when adding a new value to one of the WebGPU
enums, there is no compilation error for switches that are missing it.
Currently we're supposed to write code and tests and fix UNREACHABLEs when
we see them.

Instead we should strive to have most switches on enums to be complete
and explicitily tag unreachable values as UNREACHABLE. Some switches
might still want to use default: UNREACHABLE() if only a couple values
need to be handled out of very many.

In this CL we go through all the UNRAECHABLEs and change them if need
be. Also an ErrorQueue class is added to avoid having
QueueBase::SubmitImpl just be UNREACHABLE (and force overriding
instead).

Bug: dawn:527
Change-Id: I33dfb4703104912cc5f001f9faf907a61324de68
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/28501
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
Corentin Wallez
2020-09-24 14:56:50 +00:00
committed by Commit Bot service account
parent a46737c0aa
commit eec9edfd57
42 changed files with 136 additions and 276 deletions

View File

@@ -58,9 +58,9 @@ namespace utils {
case wgpu::TextureFormat::RGBA16Sint:
case wgpu::TextureFormat::RGBA32Sint:
return "i";
default:
UNREACHABLE();
return "";
}
}
@@ -83,6 +83,7 @@ namespace utils {
case wgpu::TextureFormat::RGBA32Sint:
case wgpu::TextureFormat::RGBA32Float:
return true;
default:
return false;
}
@@ -158,9 +159,7 @@ namespace utils {
case wgpu::TextureFormat::Depth24Plus:
case wgpu::TextureFormat::Depth24PlusStencil8:
case wgpu::TextureFormat::Undefined:
default:
UNREACHABLE();
return 0u;
}
}
@@ -224,9 +223,7 @@ namespace utils {
return 4u;
case wgpu::TextureFormat::Undefined:
default:
UNREACHABLE();
return 0u;
}
}
@@ -290,9 +287,7 @@ namespace utils {
return 4u;
case wgpu::TextureFormat::Undefined:
default:
UNREACHABLE();
return 0u;
}
}
@@ -386,7 +381,6 @@ namespace utils {
case wgpu::TextureFormat::Depth24PlusStencil8:
case wgpu::TextureFormat::Undefined:
UNREACHABLE();
return "";
}
}
} // namespace utils