A Framework for Analysis of Typed Logic Programs (original) (raw)
Related papers
Type analysis of prolog using type graphs
Journal of Logic Programming, 1995
Type analysis of Prolog is of .primary importance for high-performance compilers since type information may lead to better indexing and to sophisticated specializations of unification and built-in predicates, to name a few. However, these optimization often require a sophisticated type inference system capable of inferring disjunctive and recursive types, and hence expensive in computation time. The purpose of this paper is to describe a type analysis system for Prolog based on abstract interpretation and type graphs (i.e., disjunctive rational trees) with this functionality. The system (about 15,000 lines of C) consists of the combination of a generic fixpoint algorithm, a generic pattern domain, and a type graph domain. The main contribution of the paper is to show that this approach can be engineered to be practical for medium-sized programs without sacrificing accuracy. The main technical contribution to achieve this result is a novel widening operator for type graphs which appears to be accurate and effective in keeping the sizes of the graphs, and hence the computation time, reasonably small. <] 1. INTRODUCTION Although Prolog is an untyped language, type analysis of the language is important since it allows the improvement of indexing, to specialize unification, and to pro-*This paper is a revised and extended version of [27].
Finite-tree analysis for constraint logic-based languages
Information and Computation, 2004
Logic languages based on the theory of rational, possibly infinite, trees have much appeal in that rational trees allow for faster unification (due to the safe omission of the occurs-check) and increased expressivity (cyclic terms can provide very efficient representations of grammars and other useful objects). Unfortunately, the use of infinite rational trees has problems. For instance, many of the built-in and library predicates are ill-defined for such trees and need to be supplemented by run-time checks whose cost may be significant. Moreover, some widely-used program analysis and manipulation techniques are correct only for those parts of programs working over finite trees. It is thus important to obtain, automatically, a knowledge of the program variables (the finite variables) that, at the program points of interest, will always be bound to finite terms. For these reasons, we propose here a new dataflow analysis, based on abstract interpretation, that captures such information. We present a parametric domain where a simple component for recording finite variables is coupled, in the style of the open product construction of Cortesi et al., with a generic domain (the parameter of the construction) providing sharing information. The sharing domain is abstractly specified so as to guarantee the correctness of the combined domain and the generality of the approach. This finite-tree analysis domain is further enhanced by coupling it with a domain of Boolean functions, called finite-tree dependencies, that precisely captures how the finiteness of some variables influences the finiteness of other variables. We also summarize our experimental results showing how finite-tree analysis, enhanced with finite-tree dependencies, is a practical means of obtaining precise finiteness information.
More Precise Yet Efficient Type Inference for Logic Programs
Lecture Notes in Computer Science, 2002
Type analyses of logic programs which aim at inferring the types of the program being analyzed are presented in a unified abstract interpretation-based framework. This covers most classical abstract interpretation-based type analyzers for logic programs, built on either top-down or bottom-up interpretation of the program. In this setting, we discuss the widening operator, arguably a crucial one. We present a new widening which is more precise than those previously proposed. Practical results with our analysis domain are also presented, showing that it also allows for efficient analysis.
Type dependencies for logic programs using ACI-unification
Theoretical Computer Science, 2000
This paper presents a new notion of typing for logic programs which generalizes the notion of directional types. The generation of type dependencies for a logic program is fully automatic with respect to a given domain of types. The analysis method is based on a novel combination of program abstraction and ACI-uniÿcation which is shown to be correct and optimal. Type dependencies are obtained by abstracting programs, replacing concrete terms by their types, and evaluating the meaning of the abstract programs using a standard semantics for logic programs enhanced by ACI-uniÿcation. This approach is generic and can be used with any standard semantics. The method is both theoretically clean and easy to implement using general purpose tools. The proposed domain of types is condensing which means that analyses can be carried out in both top-down or bottom-up frameworks with no loss of precision for goal-independent analyses. The proposed method has been fully implemented within a bottom-up approach and the experimental results are promising.
A synthesis of type-checking and parsing
Computer Languages, 1993
Al~traet--The context-free grammars and parsers conventionally used to define and interpret concrete syntax lead to constrained expression notations. This paper gives algorithms which support less constrained, more intuitive notations. These algorithms can be viewed as context-sensitive parsers, where the context that is taken into account is the type structure of the expression. Or they can be viewed as type checkers that determine the form of the abstract syntax. The approach taken seamlessly integrates parsing and type-checking in the formalism of Markov algorithms. The interpretation of concrete syntax by these algorithms is unambiguous. At least one algorithm, DMA-T, is practical; its worst case time is O(tn 2) where n is the length of the expression and t is the maximum length of any type expression.
Non-termination Analysis of Logic Programs Using Types
Lecture Notes in Computer Science, 2011
In recent years techniques and systems have been developed to prove non-termination of logic programs for certain classes of queries. In previous work, we developed such a system based on mode-information and a form of loop checking performed at compile time. In the current paper we improve this technique by integrating type information in the analysis and by applying non-failure analysis and program specialization. It turns out that there are several classes of programs for which existing non-termination analyzers fail and for which our extended technique succeeds in proving non-termination.
Domain construction for mode analysis of typed logic programs
1997
There are many applications where precise mode analysis is required. However, within the framework of abstract interpretation, the precision of an analyser depends, in part, on the expressiveness of the abstract domain and its associated abstraction function. This paper considers abstract domains for polymorphically typed logic programs where each nonvariable symbol is explicitly typed. We show how to construct precise domains and their abstraction functions that re ect the declared structure of terms. This domain construction is modular in that an abstract domain for a type does not depend on modules that import this type. A program is abstracted by replacing the uni cation operations with abstract uni cation operations. The precision of the domains is demonstrated for several examples using G odel programs. Correctness of the method is proven. The domain construction has been implemented in G odel.
Optimizing the runtime processing of types in a higher-order logic programming language
2005
The traditional purpose of types in programming languages of providing correctness assurances at compile time is increasingly being supplemented by a direct role for them in the computational process. In the specific context of typed logic programming, this is manifest in their effect on the unification operation. Their influence takes two different forms. First, in a situation where polymorphism is permitted, type information is needed to determine if different occurrences of the same name in fact denote an identical constant. Second, type information may determine the specific form of a binding for a variable. When types are needed for the second purpose as in the case of higher-order unification, these have to be available with every variable and constant. However, in many situations such as first-order and higher-order pattern unification it turns out that types have no impact on the variable binding process. As a consequence, type examination is needed in these situations only for the first of the two purposes described and even here a careful preprocessing can considerably reduce their runtime footprint. We develop a scheme for treating types in these contexts that exploits this observation. Under this scheme, type information is elided in most cases and is embedded into term structure when this is not entirely possible. Our approach obviates types when properties known as definitional genericity and type preservation are satisfied and has the advantage of working even when these conditions are violated.