From 6a2050654134e9da87e7be86c4b9ea80168b42a2 Mon Sep 17 00:00:00 2001 From: Frederik Hennig <frederik.hennig@fau.de> Date: Fri, 2 Feb 2024 21:09:57 +0100 Subject: [PATCH] removed unnecessary undetType + minor fixes --- src/pystencils/nbackend/ast/kernelfunction.py | 15 ++++---- .../kernelcreation/transformations.py | 5 ++- .../nbackend/kernelcreation/typification.py | 37 +------------------ 3 files changed, 11 insertions(+), 46 deletions(-) diff --git a/src/pystencils/nbackend/ast/kernelfunction.py b/src/pystencils/nbackend/ast/kernelfunction.py index 58f2ddf36..e3c91d83c 100644 --- a/src/pystencils/nbackend/ast/kernelfunction.py +++ b/src/pystencils/nbackend/ast/kernelfunction.py @@ -46,14 +46,13 @@ class PsKernelParametersSpec: elif var in self.params: continue - - else: - raise PsInternalCompilerError( - "Constrained parameter was neither contained in kernel parameter list " - "nor associated with a kernel array.\n" - f" Parameter: {var}\n" - f" Constraint: {constraint.condition}" - ) + + raise PsInternalCompilerError( + "Constrained parameter was neither contained in kernel parameter list " + "nor associated with a kernel array.\n" + f" Parameter: {var}\n" + f" Constraint: {constraint.condition}" + ) class PsKernelFunction(PsAstNode): diff --git a/src/pystencils/nbackend/kernelcreation/transformations.py b/src/pystencils/nbackend/kernelcreation/transformations.py index c01016d12..c73fbce73 100644 --- a/src/pystencils/nbackend/kernelcreation/transformations.py +++ b/src/pystencils/nbackend/kernelcreation/transformations.py @@ -19,8 +19,9 @@ NodeT = TypeVar("NodeT", bound=PsAstNode) class EraseAnonymousStructTypes(IdentityMapper): """Lower anonymous struct arrays to a byte-array representation. - Arrays whose element type is an anonymous struct are transformed to arrays with element type UInt(8). - Lookups on accesses into these arrays are transformed using type casts. + For arrays whose element type is an anonymous struct, the struct type is erased from the base pointer, + making it a pointer to uint8_t. + Member lookups on accesses into these arrays are then transformed using type casts. """ def __init__(self, ctx: KernelCreationContext) -> None: diff --git a/src/pystencils/nbackend/kernelcreation/typification.py b/src/pystencils/nbackend/kernelcreation/typification.py index c817bde3f..37ed8e8e1 100644 --- a/src/pystencils/nbackend/kernelcreation/typification.py +++ b/src/pystencils/nbackend/kernelcreation/typification.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TypeVar, Any, NoReturn +from typing import TypeVar, Any import pymbolic.primitives as pb from pymbolic.mapper import Mapper @@ -10,7 +10,6 @@ from ..types import PsAbstractType, PsNumericType, PsStructType, deconstify from ..typed_expressions import PsTypedVariable, PsTypedConstant, ExprOrConstant from ..arrays import PsArrayAccess from ..ast import PsAstNode, PsBlock, PsExpression, PsAssignment -from ..exceptions import PsInternalCompilerError __all__ = ["Typifier"] @@ -22,40 +21,6 @@ class TypificationError(Exception): NodeT = TypeVar("NodeT", bound=PsAstNode) -class UndeterminedType(PsNumericType): - """Placeholder for types that could not yet be determined by the typifier. - - Instances of this class should never leave the typifier; it is an error if they do. - """ - - def create_constant(self, value: Any) -> Any: - return None - - def _err(self) -> NoReturn: - raise PsInternalCompilerError("Calling UndeterminedType.") - - def create_literal(self, value: Any) -> str: - self._err() - - def is_int(self) -> bool: - self._err() - - def is_sint(self) -> bool: - self._err() - - def is_uint(self) -> bool: - self._err() - - def is_float(self) -> bool: - self._err() - - def __eq__(self, other: object) -> bool: - self._err() - - def c_string(self) -> str: - self._err() - - class DeferredTypedConstant(PsTypedConstant): """Special subclass for constants whose types cannot be determined yet at the time of their creation. -- GitLab